Apopstrophes in SQL from code

Sally

Registered User.
Local time
Today, 23:49
Joined
Feb 6, 2002
Messages
12
I need an apostrophe in part of a SQL statement I'm constructing from code. The code works if I take it out but I get a ByRef error if I put it in. I've tried looking at previous posts but still can't sort it out. Please help
 
can you post your SQL string please.
Normally you have to enclose apostrophes in double quotes and concatenate the strings on either side of it with & operators
 
You will need to format your SQL with these things in mind:

Access 2000
===========
strMyName="Samual's Toys"
SQL="Select * from [MyTable] Where [MyName]='" & replace(strMyName,"'","''") & "'"

Pre Access 2000
===============
strMyName="Samual's Toys"
SQL="Select * from [MyTable] Where [MyName]=""" & strMyName & """"
 
Whenever your text string may contain single quotes, you must surround it with double quotes.
 
Thanks very much one and all:
I had tried "'" i.e. " ' " but not
"''" i.e. " ' ' "! - this was my first proper foray into SQL and it works now, so thank you.... I'm not sure how I'd manage without the forum to search/ post to
 

Users who are viewing this thread

Back
Top Bottom