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 
Turn filtered off
Robert Freeman 
      
3 years ago
Hi. I have a search button created after watching Richard's video and that works fine. Unfortunately when it is run by a user that has read only access and there is nothing to find it returns a blank page and, because the form is read only, will not let you manually turn the filter off.
Is there a way to display a message box "nothing found" and then turn the filter off using VBA.
The current vba script is currently as Follows:

Private Sub SearchFirstNameBtn_Click()
    Dim S As String    
    S = InputBox("Enter Search Criteria", "FirstName", "Enter First Name or Part Of First Name ?")
    If S = "" Then Exit Sub    
    Me.Filter = "FirstName LIKE ""*" & S & "*"""
    Me.FilterOn = True      
End Sub
Adam Schwanz  @Reply  
            
3 years ago
You could just DCount to check how many records have "FirstName LIKE ""*" & S & "*""" and if there aren't any, then turn off the filter.
Kevin Robertson  @Reply  
          
3 years ago
Here is a slightly more complicated solution that allows the user to search based on first name or last name while eliminating the need for duplicate code.
Kevin Robertson  @Reply  
          
3 years ago

Kevin Yip  @Reply  
     
3 years ago
In VBA, a form's recordset's recordcount property gives you the number of rows in the form:

     Me.Recordset.RecordCount     ' Current form
     Me.MySubform.Form.Recordset.RecordCount     ' Current form's subform
     Forms!MyForm.Recordset.RecordCount     ' Any form
     Forms!MyForm.MySubform.Form.Recordset.RecordCount     ' Any form's subform

If you put a textbox in the form's footer with the control source =Count(*) , it will also show the form's row count, but it will not show zero when there is no record.  And it's a headache to make it show zero in that situation.  Let me know if you need this method.
Robert Freeman OP  @Reply  
      
3 years ago
Thank you all. It's now working fine with Kevin's code.

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/2/2026 1:32:54 AM. PLT: 1s