Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Search As You Type    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Run Time Error 2185
Todd Clapp 
    
16 months ago
This error is driving me crazy and I can't figure out where I'm going wrong. As I type in the SearchBox and there are no records the focus moves away from the SearchBox and the Run Time Error is thrown. It is the exact same code as the example but it does not work on my own sample database. UGH.


Private Sub SearchBox_Change()
    
    Me.RecordSource = "SELECT * FROM EntityT " & _
        "WHERE " & _
            "OrganizationName LIKE ""*" & SearchBox.Text & "*"""
            
    SearchBox.SetFocus
    SearchBox.SelStart = Len(SearchBox.Text)

End Sub
Kevin Robertson  @Reply  
          
16 months ago
What is the Runtime Error?
Todd Clapp OP  @Reply  
    
16 months ago
Hi Kevin. Run Time Error '2185'
Todd Clapp OP  @Reply  
    
16 months ago
And it always highlights the line of code "SearchBox.SelStart = Len(SearchBox.Text)
Todd Clapp OP  @Reply  
    
16 months ago
I should have read more of the questions. Did not have Allow Additions turned on.
Todd Clapp OP  @Reply  
    
16 months ago
The Allow Additions does work when I search from a table but if I change the record source to a Query I'm getting the Run Time Error 2185 again.
Todd Clapp OP  @Reply  
    
16 months ago
After some more testing I'm noticing as you search a Query and come up with no results the SearchBox looses focus and the Run Time Error 2185 is thrown. The error in the code says "SearchBox.Text = <You can't reference a property or method for a control unl... (not sure how to show the rest of the error in the VB editor).

I guess my question is how do I stop the SearchBox from loosing focus when the search results return nothing?

Another bit of information. The Query includes a customerID, CusterName, InventoryCount (Count of active inventory items)
Kevin Robertson  @Reply  
          
16 months ago
Here is a fix for you if you want Allow Additions set to False.

DetailsPrivate Sub SearchBox_Change()

    On Error GoTo Errorhandler
    
    Me.RecordSource = "SELECT * FROM EntityT " & _
        "WHERE " & _
            "OrganizationName LIKE ""*" & SearchBox.Text & "*"""
            
    SearchBox.SetFocus
    SearchBox.SelStart = Len(SearchBox.Text)
    Exit Sub
    
Errorhandler:
    If Err.Number = 2185 Then
        Me.RecordSource = "SELECT * FROM EntityT WHERE EntityID=0"
    End If
    
End Sub
Richard Rost  @Reply  
          
16 months ago
Genius solution, Kevin Robertson
Todd Clapp OP  @Reply  
    
16 months ago
Thanks Kevin. That works perfectly and a reminder to learn more about Errorhandling. Thanks again.
Kevin Robertson  @Reply  
          
16 months ago
You're welcome.

Here is a video on basic Error Handling.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Search As You Type.
 

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: 6/14/2026 11:04:54 PM. PLT: 0s