Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Convert excel code into Access
Qandeel Ayyaz 
   
3 years ago
Is there a way i can apply this excel code in access. It scans and colors the cell orange, part numbers are scanned in the b2 cell and items are colored in the part numbers column if they match the scanned number, the matching number is colored orange in the part numbers column. How do i do something like this in access :
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Me.Range("b2")) Is Nothing Then
    
        Call orange
        Application.EnableEvents = True
    End If
End Sub

Module:
Sub orange()
Dim barcode As String
Dim rng As Range
Dim rownumber As Long
If Sheet1.Cells(1, 23) <> "" Then
barcode = Sheet1.Cells(1, 23)

    Set rng = Sheet1.Columns("b:b").Find(What:=barcode, _
    LookIn:=xlFormulas, LookAt:=xlWhole, searchorder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    
    If rng Is Nothing Then
        MsgBox "Not Found"
        Exit Sub
    Else
        rownumber = rng.Row
        Sheet1.Cells(rownumber, 2).Select
        ActiveCell.Interior.ColorIndex = 45
        Sheet1.Cells(1, 23) = ""
            
    End If
    Sheet1.Cells(1, 23).Select
    
  End If
End Sub
Qandeel Ayyaz OP  @Reply  
   
3 years ago

Gregory Clancey  @Reply  
    
3 years ago
I wonder if you could have conditional formatting do some of this. It seems to me that even if not once the data has been displayed on your Form, the values in the various TextBoxes could be programmatically reviewed and compared to other data as the need requires and formatting cues -- such as backColor, ForeColor, Alignment, Font Style etc. . . -- could be assigned. My impression is that you will find Access MORE flexible than Excel in this regard.
Qandeel Ayyaz OP  @Reply  
   
3 years ago
I tried Conditional formatting using expression is: [Part_Number] = [Scan] but it does not work like this i want to go scan scan scan and the matching items get colored and count the colored items. but conditional formating does a single entry.
Qandeel Ayyaz OP  @Reply  
   
3 years ago

Gregory Clancey  @Reply  
    
3 years ago
I see your point. It's a bit of a task, for sure. Corresponding to the "columns" in an Excel Worksheet, you will have an Access data table. That's probably the best place to "scan" via a query. If your query includes both the table with the data to be accessed and a second table containing the values against which your comparing, you'd have to work out some way to "flag" matches. Maybe a field added to the original assessed data table into which an updateQuery could place a code which your display form could use as a guide for creating the formats. I'm speaking generally, I know. You'd have to try various things with your data to see what works.

There's the essential difference between the two titles. Excel is up-and-running almost immediately, but has inflexibily, while Access can be made to accommodate many ends, yet requires a great deal more planning and organizing.

My advice is to start with a new Access database and include, there, the several tables -- derived from your Excel worksheets, but with many fewer rows to keep the initial work simplified. Try querying to find significant matches as you have indicated. When brought onto a form, I expect "Continuous" will be best. An alternative to your Paradym of using formatting, perhaps show the compare result in a separate TextBox also displayed on the Form.

For example "PN xxxx5123" and "This matches an inventory item".

These data, once fully queried, could be displayed on the Form grouped by the criteria.

This is the sort of project that will help you teach yourself how to use Access. Nothing comes "right out of the box."
Kevin Yip  @Reply  
     
3 years ago
You can have multiple conditional formats for the same field.  See picture below.
Kevin Yip  @Reply  
     
3 years ago

Gregory Clancey  @Reply  
    
3 years ago
Oh, that's right. I had forgotten. I always sort of avoid conditional formatting because I read it uses a lot of processing real estate and tends to slow down performance. At least in my early days, everything was done to avoid the need for expensive RAM and storage capacity and the chips of the day were easily slowed to a crawl by any extraneous data. I wonder if I should still be so paranoid given the vast improvement in capacity and cost of equipment. I have been using some such formatting, but my tables are relatively small. It might be worth it for this fellow to try an all conditional-formatting solution?
Qandeel Ayyaz OP  @Reply  
   
3 years ago
Thanks a lot learned lots from these tips. Before coming here i researched a lot on this topic and i found a method called the find first, do while loop function, but i dont know any vba. And i could not find anything related to this function neither on youtube or anywhere else. I asked bing chat and google bard as well. they suggested this find first method but i dont know how to create it . Sir Richard rost once said in a video to tell him if i dont find anything online related to access. Can i request a video for this find First function? It looks kinda like this:
    Sub FindOrgName()
    
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset
        
        'Get the database and Recordset
        Set dbs = CurrentDb
        Set rst = dbs.OpenRecordset("tblCustomers")
    
        'Search for the first matching record  
        rst.FindFirst "[OrgName] LIKE '*parts*'"
        
        'Check the result
        If rst.NoMatch Then
            MsgBox "Record not found."
            GotTo Cleanup
        Else
            Do While Not rst.NoMatch
                MsgBox "Customer name: " & rst!CustName
                rst.FindNext "[OrgName] LIKE '*parts*'"
            Loop
    
            'Search for the next matching record
            rst.FindNext "[OrgName] LIKE '*parts*'"
        End If
      
        Cleanup:
            rst.Close
            Set rst = Nothing
            Set dbs = Nothing
    
    End Sub
Gregory Clancey  @Reply  
    
3 years ago
Try MS's https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/recordset-findfirst-method-dao
Gregory Clancey  @Reply  
    
3 years ago
Do you know how RecordSet lets you use your data tables in code? FindFirst is used in conjuction with "If Not NoMatch." There's a lot to cover, but it makes sense. Google around for DAO Recordsets in MS Access. Rich has a couple of TechHelp videos on YouTube (https://www.youtube.com/watch?v=qHLQTRhU7BE, and others). He's always worth the time -- and it's free. Lots of other qualified presenters there as well.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 8/7/2026 8:56:27 PM. PLT: 1s