Page 1 of 1

Updating in Access- quotes

Posted: Thu Jul 05, 2007 5:42 pm
by gimpeltf
I'm having trouble Updating a field when there's an apostrophe (single quote) in the field. The same code put directly into Access works fine so it has to do with the interface.

put "Update Campers Set LastName='" & fld LastName & "' where ID=" & fld WID & ";" into uQuery
put revdb_execute(tConnectionID,uQuery) into dummy

Of course, there would be a problem with unmatched quotes in the above if the Name was O'Boyle.
I've taken out the single quotes in the code and replaced with & quote.
the value in uquery wouls be
Update Campers Set LastName="O'Boyle" where ID=365;
This code would work directly in Access but returns an error of
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

Any thoughts?

Gimp

Posted: Fri Jul 06, 2007 10:17 am
by Mark
Dear Gimp,

I'm not an experienced Access user, but don't you have to escape the additional quote in O'Neil? Are you sure Access understands if you exchange all apastrophes and double quotes?

Try

Update Campers Set LastName='O\'Boyle' where ID=365;

(I believe it is a backslash, it might be a slash).

Mark

Posted: Sat Jul 07, 2007 4:46 am
by gimpeltf
Mark wrote:Dear Gimp,

I'm not an experienced Access user, but don't you have to escape the additional quote in O'Neil? Are you sure Access understands if you exchange all apastrophes and double quotes?

Try

Update Campers Set LastName='O\'Boyle' where ID=365;

(I believe it is a backslash, it might be a slash).

Mark
Thanks but "O'Neil" works within access but not within revolution. I tried the escaping with a slash but it didn't help.

Posted: Sat Jul 07, 2007 5:18 am
by gimpeltf
I think I found the solution. I just found out that two consecutive single quotes is treated by Access as one single quote. Therefore, by replacing any quotes in a field with pairs of quotes will allow the proper passing of the string query parameter and the final value seen in Access has only one quote.
And thanks, because your suggestion led me to the answer.