2185 Error on Subform Search (1 Viewer)

Zippersabrat

Blah Blah Blah :o)
Local time
Yesterday, 21:25
Joined
May 5, 2010
Messages
31
:confused:

Hello everyone! I have the below code on a subform. The search works fine IF the item is on the list. However, if the item is not on the list, it gives a 2185 error. WHY?! And how do I fix it? When I debug it highlights the Me.Searchbox.SelStart = Len(strSearch) line.

TIA

Code:
Private Sub SearchBn_Click()

Dim strSearch As String, _
    strFilter As String
    
    Me.Refresh
 
    If IsNull(Me.SearchBox) Then
            Me.SearchBox = "*"
    End If
    strSearch = Me.SearchBox.Value
     
    strFilter = "Searchable like '*" & strSearch & "*'"
    Me.Form.Filter = strFilter
    Me.Form.FilterOn = True
 
    If Not IsNull(Len(strSearch)) Then
        Me.SearchBox.SetFocus
        Me.SearchBox.SelStart = Len(strSearch)
            If IsNull(Searchable) Then
                MsgBox ("The search " & Me.SearchBox & " returned no results."), vbOKOnly + vbInformation, "Sorry"
                Me.Form.FilterOn = False
            End If
                Me!SearchBox = Null
    End If
    
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:25
Joined
Oct 29, 2018
Messages
21,496
Hi,

What happens if you step through the code? What is error 2185?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 00:25
Joined
May 21, 2018
Messages
8,555
This is one of your problems
Code:
Not IsNull(Len(strSearch))
That does not do anything. StrSearch is a string. Even if you do nothing the len of it is zero since the default is "". It can never be null.
 

June7

AWF VIP
Local time
Yesterday, 20:25
Joined
Mar 9, 2014
Messages
5,488
If Searchable is a field, suggest use IsNull(Me!Searchable)

Test if strSearch = ""

Try:

If Not IsNull(Me.SearchBox) Then Me.SearchBox.SelStart = Len(strSearch)
 
Last edited:

Users who are viewing this thread

Top Bottom