2185 Error on Subform Search

Zippersabrat

Blah Blah Blah :o)
Local time
Yesterday, 23:36
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
 
Hi,

What happens if you step through the code? What is error 2185?
 
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.
 
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

Back
Top Bottom