Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking Up Strings With SQL

Status
Not open for further replies.

matzos

Programmer
Aug 22, 2001
38
US
I need some help. I have forms that are performing a lookup based on the text selected in a list box. The SQL statement uses "...WHERE ClientName = " & "'" & lstClient.Text & "'"

This works for all occurences except if a ClientName has an apostrophe in the name itself...the SQL things that it is the end of the string and it gives me a run-time error because it also uses the apostrophe to mark the text. If I remove the surrounding apostrophes, the statement will not work at all.

I need to know how to lookup a string without using the surrounding apostrophes. I have tried several ideas but I am stuck.

I appreciate whetever help you can give! Thanks.
 
Use the replace function (common fix):
YourString = Replace(recordset.fieldname, "'", "''")
Where the first instance is a single quote surrounded by double quotes and the second instance is two single quotes surrounded by double quotes. Works like a charm for me!!
-Geno
 
faq222-418 covers this too.

Wil Mead
wmead@optonline.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top