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

Parsing string constant with " in sql query

Status
Not open for further replies.

swansea68

Programmer
Aug 22, 2002
1
US
I have a query constructed to update to table tQA. My problem is that both the Question and Answer fields are character string. The Execute complete with no error when both Question and Answer fields conatin no '"' (double quote) character, however when any of them conatin the double quote character, I get a syntax error in query expression.

strSQLnew = "UPDATE tQA SET Question = """ & oRS![Question] & """, " & "Answer = """ _
& oRS![Answer] & """, " & "Comments = """ & oRS![Comments] & """" _
& " WHERE ID = " & oRS![ID]
CurrentProject.Connection.Execute strSQLnew

How can I avoid such error? Is there another way to construct and execute a query that allows the " as part of the value of the field?

 
Check out strQuote approach in Help file... Search for "Quotation Marks in Strings"... htwh Steve Medvid
"IT Consultant & Web Master"
e-Mail: Stephen_Medvid@GMACM.com

Chester County, PA Residents
Please Show Your Support...
 
Same error to me. Just change the " for ' (Apostrophe) or use chr$(33) instead. Have a nice day! To boldly code, where no programmer has compiled before!
 
Aristarco,

If I change the " for ', now the query will give me a syntax error during excution when my string value contains a '.

-Swan
 
simma,

in my programs I tried this :

Dim strSQL As String
Dim Dlm As String
Dlm = "'"
If InStr([Field2], "'") > 0 Then Dlm = """"
strSQL = "UPDATE tab2 SET Field2 = " & Dlm & _
[Field2] & Dlm & " where field1 = " & Dlm & [Field1] & Dlm
CurrentDb.Execute strSQL

but this still don't work if you have " and ' in the field.
Than I generate an errormassage and resume to form.

Hope it will help a little.

- FirstDirk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top