Full Version: Search Form Won't Search Names With Apostrophe
UtterAccess Forums > Microsoft® Access > Access Forms
aguzman
I have a search form to search by company name but when you search for a company with an apostrophe I get an error.
THere is my sql string for company name
If Not IsNull(Me.txtCompanyName) Then
If sql <> " WHERE " Then
sql = sql & " And "
End If
ok = True
sql = sql & "[CompanyName] LIKE '*" & Me.txtCompanyName & "*'"
How can I adjust this to allow the user to search out a company with an apostrophe.
Alan_G
Hi
You need to 'double up' the apostrophe. Try -
CODE
sql = sql & "[CompanyName] LIKE '*" & Replace(Me.txtCompanyName,"'","''") & "*'"
aguzman
thank you so much, works perfect.
aguzman
One more thing if you can help again.
That fixed the apostrophe problem but now I'm noticing that the search would not find any company names with periods in them. For example we have a company name that starts with W.W. XYZ inc. The results are blank but if I enter the company name like XYX Inc. then it works.
aguzman
For get that last post, user error..lol
Thanks for all your help.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.