Hi all,
Probably and easy fix, but I'm not sure what that its. Thanks in advance for advice.
I have a TextBox in header of two continuous forms that I use to filter the form as I type. As long as I don't make any mistakes it works just great. But if I add a letter to the name that results in no records, Access gives me an error.
Here is the code:
Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please feel free to Remove this Comment
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
The error happens on the last line of the sub.
Thanks!
Probably and easy fix, but I'm not sure what that its. Thanks in advance for advice.
I have a TextBox in header of two continuous forms that I use to filter the form as I type. As long as I don't make any mistakes it works just great. But if I add a letter to the name that results in no records, Access gives me an error.
Here is the code:
Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please feel free to Remove this Comment
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Code:
Private Sub txtFilter_Change()
' If the text box is cleared, clear the form filter.
If Nz(Me.txtFilter.Text) = "" Then
Me.Form.Filter = ""
Me.FilterOn = False
' If a partial value is typed, filter for a partial company name match.
Else
Me.Form.Filter = "[CompanyName] Like '*" & Replace(Me.txtFilter.Text, "'", "''") & "*' OR [ContactName] Like '*" & Replace(Me.txtFilter.Text, "'", "''") & "*'"
Me.FilterOn = True
End If
' Move the cursor to the end of the combo box.
Me.txtFilter.SetFocus
Me.txtFilter.SelStart = Len(Me.txtFilter.Text)
End Sub
The error happens on the last line of the sub.
Thanks!
Last edited by a moderator: