EternalMyrtle
I'm still alive
- Local time
- Today, 14:53
- Joined
- May 10, 2013
- Messages
- 533
Hello
I am using the following code to filter my form with a search box:
It works great with one minor issue: if I try to search for a name containing an apostrophe, I get a syntax error. So, it won't find Children's Hospital for example.
Can anyone tell me how to alter the code so that I won't have this problem?
Thank you!
I am using the following code to filter my form with a search box:
Code:
Me.RecordSource = "qryCompanies"
Me.Filter = "CompanyName Like '*" & Me.SearchTxt & "*' Or webpage Like '*" & Me.SearchTxt & "*' Or PriorName Like '*" & Me.SearchTxt & "*'"
Me.FilterOn = True
'Show message box if no records are found and set focus on search box
If DCount("*", Me.RecordSource, Me.Filter) = 0 Then
MsgBox "No Results Found. Please try again", , "No Records Found"
Me.FilterOn = False
Me.SearchTxt = Null
Me.SearchTxt.SetFocus
End If
It works great with one minor issue: if I try to search for a name containing an apostrophe, I get a syntax error. So, it won't find Children's Hospital for example.
Can anyone tell me how to alter the code so that I won't have this problem?
Thank you!