Solved Search inc backspace

Kayleigh

Member
Local time
Today, 20:05
Joined
Sep 24, 2020
Messages
709
Hi,
I have this function which works great to search within continuous form however when I backspace in the search box, it doesn't amend the search results. Can anyone suggest how this would be possible?
Code:
Private Sub SearchFor_Change()

On Error GoTo Err_SearchFor_Change
 Dim strFilter As String
    If Not IsNothing(Me.SearchFor.Text) Then
        If Not IsNothing(Me.Filter) Then
                strFilter = Me.Filter & " AND "
        End If
            strFilter = strFilter & " ( [cfStaffName] Like '*" & Me.SearchFor.Text & "*' OR [fldDNote] Like '*" & Me.SearchFor.Text & "*' OR [fldDComment] Like '*" & Me.SearchFor.Text & "*' )"
        
        Me.Filter = strFilter
        Me.FilterOn = True
    End If
    With Me.SearchFor
        .SetFocus
        .SelStart = Len(Me.SearchFor.Text)
    End With
    Exit Sub
 
Does the event fire when you backspace? If so, have you tried stepping through it?
 
Figured it out. It was always adding to the current filter instead of overwriting it!
 
Code:
Private Sub SearchFor_Change()
Dim t As String
t = Me.SearchFor.Text & ""
On Error GoTo Err_SearchFor_Change
 Dim strFilter As String
    If Not isnothing(t) Then
        If Not isnothing(Me.Filter) Then
                strFilter = Me.Filter & " AND "
        End If
            strFilter = strFilter & " ( [cfStaffName] Like '*" & t & "*' OR [fldDNote] Like '*" & t & "*' OR [fldDComment] Like '*" & t & "*' )"
        
        Me.Filter = strFilter
        Me.FilterOn = True
    End If
    With Me.SearchFor
        .SetFocus
        .Value = t
        .SelStart = Len(t)
        .SelLength = 0
    End With
    Exit Sub
 

Users who are viewing this thread

Back
Top Bottom