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 Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Text Box for Searching
Daniel Golden 
     
16 months ago
I am going to attach a photo of the VBA code for the search box on my form. It works somewhat well in that whatever data is entered in the box, the form searches for it. I have observed though that when data is entered, such as an inmate involved, then cleared, the form ONLY allows those records related to the inmate name, or number, to be searched rather than all the records which were available to search prior to entering the data in the search box.
Daniel Golden OP  @Reply  
     
16 months ago

Daniel Golden OP  @Reply  
     
16 months ago
Also, when data is entered in the search box that does not exist in the underlying table, it returns the dreaded run-time error '2185'. How can I get around that and perhaps have a msgbox pop up that tells my users the data entered is not found instead.
Richard Rost  @Reply  
          
16 months ago
That's because you're turning a filter on. You need to turn it off when you're done with it. Personally, I don't like using filters. I prefer the Where Condition. See DoCmd.OpenForm.
Richard Rost  @Reply  
          
16 months ago
If you want to have the search fields on the same form and not open another one, you can change the RecordSource property with new SQL.
Daniel Golden OP  @Reply  
     
16 months ago
Richard,

My search box is on the same form. When a user backspaces all data out of the search box, the form resets to the first entry in the table. I guess what I am trying to find out is if there is any code which when the clear button it will reset the form so that all records again become available as they do when the users backspaces the data out, currently, all it does is clears the data from the search box and nothing else. And also how to prevent the run-time error '2185' when a user enters data not present in the table.
John Davy  @Reply  
         
16 months ago
Hi Daniel
Here is some vba from an old App Modify it as needed. HTH  Richard's Search Seminar is excellent

DetailsPrivate Sub txtSearch_AfterUpdate()
   Dim strsearch As String
   Dim Task As String
   'Check if a keyword entered or not
   If IsNull(Me.txtSearch) Or Me.txtSearch = "" Then
   MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed"
   Me.txtSearch.BackColor = vbYellow
   Me.txtSearch.SetFocus
Else
   strsearch = Me.txtSearch.Value
   Task = "SELECT * FROM FindCategoryAndProjectQ WHERE ((CategoryName Like ""*" & strsearch & "*""))"
   Me.RecordSource = Task
   Me.txtSearch.BackColor = vbWhite
End If
End Sub

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 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/6/2026 12:35:26 AM. PLT: 1s