Solved Search inc backspace (1 Viewer)

Krayna

Member
Local time
Today, 23:30
Joined
Sep 24, 2020
Messages
603
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:30
Joined
Oct 29, 2018
Messages
18,962
Does the event fire when you backspace? If so, have you tried stepping through it?
 

Krayna

Member
Local time
Today, 23:30
Joined
Sep 24, 2020
Messages
603
Figured it out. It was always adding to the current filter instead of overwriting it!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:30
Joined
May 7, 2009
Messages
16,393
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

Top Bottom