Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Search Box on a Form
Neal Austin 
      
9 months ago
i have watched and created a search box on my form to search for just last name only when clicked, how do i expand that to search either the customers first or last name when entered. not just the full name, but either first or last name?
Neal Austin OP  @Reply  
      
9 months ago
this is what i currently have for my last name search

Private Sub SearchByLastNameBtn_Click()

    Dim S As String, LN As String
        
        S = InputBox("Please enter Customers Last Name", "LastName")
        If S = "" Then Exit Sub
        
        LN = Nz(DLookup("LastName", "CustomerT", "LastName LIKE ""*" & S & "*"""), "")
        If LN = "" Then
            
            DoCmd.GoToRecord acDataForm, "OrderEntryF", acNewRec
            DoCmd.GoToControl "FirstName"
            
            Exit Sub
        End If
        
        Me.Filter = "LastName LIKE ""*" & S & "*"""
        Me.FilterOn = True
        
End Sub
Adam Schwanz  @Reply  
           
9 months ago
Do you want it to always search firstname or lastname? Or only sometimes? There's a lot of ways to do it, you could do a combo box to select if you want to search by first or last if you want, or checkboxes, or there are other options.

But, if you just want to search by first or last name, either at the same time, always, the simplest way is just to add an OR statement in there.

LN = Nz(DLookup("LastName", "CustomerT", "LastName LIKE ""*" & S & "*"" or FirstName Like ""*" & S & "*"""), "")
Kevin Robertson  @Reply  
          
9 months ago
Use Concatenation to build the string.

    Dim S As String, LN As String, FN As String
        
    LN = InputBox("Please enter customer's last name", "Last Name")
    If LN = "" Then Exit Sub
    
    FN = InputBox("Please enter customer's first name", "First Name")
    If FN = "" Then Exit Sub

    S = "LastName LIKE ""*" & LN & "*"" AND "
    S = S & "FirstName Like ""*" & FN & "*"""
    
    Me.Filter = S
    Me.FilterOn = True


If you are searching on more than just a couple of fields I would recommend using Form fields instead of Input Boxes.
Neal Austin OP  @Reply  
      
9 months ago
ok, thank you for the support, i will try both ways to see what happens, thanks again

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: 5/1/2026 9:51:35 PM. PLT: 1s