Hi
I am working in Access 2010. I have created a form with an ubound textbox that acts as a filter. I work as long as I dont update any fields on a record. Once the user updates a field the filter cannot find any records but the first one. I have tried Requery (the forms record source is a query) and tried turning the filters on and off but cannot get it to work correctly. The below code is on the After Update event of the unbound textbox (txtSearch)
Thanks L
Dim strFilter As String
On Error GoTo ErrHandler
If Me.txtSearch <> "" Then
'strFilter = "[BoxNumber] like '*" & Me.txtSearch.Text & "*'"
strFilter = "[BoxNumber] = """ & (Me.txtSearch) & """"
Me.Filter = strFilter
Me.FilterOn = True
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Filter returns no records"
Me.FilterOn = True
End If
Else
Me.Filter = ""
Me.FilterOn = False
End If
With Me.txtSearch
.SetFocus
.Value = " "
.SelStart = Len(Me.txtSearch.Text)
End With
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
End Sub
I am working in Access 2010. I have created a form with an ubound textbox that acts as a filter. I work as long as I dont update any fields on a record. Once the user updates a field the filter cannot find any records but the first one. I have tried Requery (the forms record source is a query) and tried turning the filters on and off but cannot get it to work correctly. The below code is on the After Update event of the unbound textbox (txtSearch)
Thanks L
Dim strFilter As String
On Error GoTo ErrHandler
If Me.txtSearch <> "" Then
'strFilter = "[BoxNumber] like '*" & Me.txtSearch.Text & "*'"
strFilter = "[BoxNumber] = """ & (Me.txtSearch) & """"
Me.Filter = strFilter
Me.FilterOn = True
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Filter returns no records"
Me.FilterOn = True
End If
Else
Me.Filter = ""
Me.FilterOn = False
End If
With Me.txtSearch
.SetFocus
.Value = " "
.SelStart = Len(Me.txtSearch.Text)
End With
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
End Sub