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 Record
Neal Austin 
      
12 months ago
trying to add extra code to this vba, trying to handle the error, when a last name is entered that is not in the records, that it will open a new record to add the customer in. here is my current code. thanks

Private Sub CustomerSearchbtn_Click()
    
    
    Dim S As String
    
    S = InputBox("Please enter Customers Last Name", "Last Name", "")
    
    
    
    If S = "" Then Exit Sub
    
    
    Me.Filter = "LastName Like ""*" & S & "*"""
    Me.FilterOn = True
    


    
End Sub
Kevin Robertson  @Reply  
          
12 months ago
You could do something like this:

    Dim S As String, LN As String
    
    S = InputBox("Please enter Customers Last Name", "Last Name")
    If S = "" Then Exit Sub
    
    LN = Nz(DLookup("LastName", "CustomerT", "LastName LIKE ""*" & S & "*"""), "")
    If LN = "" Then
        DoCmd.OpenForm "CustomerF", , , , acFormAdd
        Exit Sub
    End If
    
    Me.Filter = "LastName LIKE ""*" & S & "*"""
    Me.FilterOn = True

Neal Austin OP  @Reply  
      
11 months ago
i tried your code, and if i enter in a name that does not match, nothing happens, any ideas?
Neal Austin OP  @Reply  
      
11 months ago
Thanks for the help, i finally figured out why your code did not work for me. I took your code, deleted the docmd open form, because the form was already open, then i just added docmd then go to new record, i even added which field to start in.
thanks for the help to get there.

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:30 PM. PLT: 1s