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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for a name with an apostrophe in it using DAO

Status
Not open for further replies.

Slarti

Programmer
Feb 5, 2003
45
GB
I'm using VB to connect to an Access database. I have table of customer records and need to search for a customer by name. I'm having trouble searching for names with an apostrophe in such as O'Leary, O'Donnell etc. The SQL I'm using is SELECT * FROM tblCustomer WHERE sName LIKE '*" & sRequiredName & "*'" where sRequiredName is the parameter and is a string variable. Where am I going wrong?
Thanks in anticipation.
 
Doesn't access use double quotes as string delimiters?

Ps. Do you know where your towel is?

mmilan
 
One of the ways to get around this is to "double" up on your single quotes what I mean by that is doing something like:

sRequiredName = Replace(sRequiredName, "'", "''")

SELECT * FROM tblCustomer WHERE sName LIKE '*" & sRequiredName & "*'"


Hope this helps...
 
Best is to use a command and parameter object (check the FAQs).

Or use:

...LIKE " & Chr$(34) & "*" & sRequiredName & "*" & Chr$(34)
 
Thanks men. I'll try some of these.

Did you pinch my towel?
 


MY COMPUTER DOES NOT BOOT UP, THEN IT SHUTS DOWN AFTER SOMETIMES
 
671391 - first post - bit of an error. If you want to place a question, start your own thread, rahter than asking a separate issue question in someone else thread. Also, for anyone to be able to help you, they need more information than you have given here.

And finally, I don't think this is the forum where you want to ask that question. Try in the windows forum of tek-tips.

Good luck

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top