Avatar of generali
generali
 asked on

VBA/Access hanling apostrophe (')?

I am opening some data in a recordset and that looping through the data and running a simpe update query using docmd.runsql...my problem arises when I come accross a name that has an apostrophe in it i.e. O'Hara, then I receive a run time error. Does anybody know of a way to handle this?
Microsoft Access

Avatar of undefined
Last Comment
generali

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
peter57r

Instead of using the field directly use:
Replace(fieldname, "'", "''")
which replaces a single quote with two.
generali

ASKER
capricorn1-

tried the first one and returned - '" & Nz(rst!Debtor, ") & "' in my sql but replaced the double single quote with space and worked a treat.

Many Thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy