Just double each tick contained in a string.
Any reason why you use a INSERT ... SELECT instead of INSERT ... VALUES ...?
Main Topics
Browse All TopicsHi All,
I have setup a process loop that runs through a record set one by one to do various things.
Basically, the database imports new data from a spreadsheet daily, then the process loop selects each record, and based on a number of variables, creates windows folders, .txt files, sends an email and then moves the current to another table.
Its the part where a record gets added to an existing table thats creating the problem when the source data includes an apostrophe '
The data being added with the INSERT INTO query is already defined as a string and might be:
strContactName = "John O'Shea"
I cannot substitute the ' for another character, I cannot eliminate it, I must pass it to the table as is becuase it is translated to the persons email address which contains the apostrophe. Ie: "John.O'Shea@company.com" which is something I also pass but haven't included in the code example below.
There will not always be an apostrophe, so is there a way to change the syntax to deal with the apostrophe that will not affect other records not containing an apostrophe?
An example of the code portion is noted below:
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
thanks for the quick suggestion pcelba! I had tried this previously and it didn't work. I just tried again and the error is still 3075-Syntax Error.
I'll try and elaborate further. The ContactName is imported as "John O'Shea"
From this I then translate two things:
strContactName = (some code to break our the first name) = "John"
strContactEmail = (some code to translate John O'Shea into John.O'Shea@company.com)
I then refer to these two strings in the INSERT INTO query exactly the same as noted above. So the replace function added above returns in the error message (John O''Shea) effectively giving the same error.
Qlemo, by tick, do you mean ' (apostrophe?) ?
I just tried doubling the opening and closing apostrophe and this results in the same syntax error.
And I use select for not real reason only that its the only way I knew how - I'm self taught....so you don't know what you haven't discovered or been told before...
Could you please post the whole command created by the expression:
" INSERT INTO tbl_CurrentQuotes (SystemID, QuoteNumber, CustomerName, Contact)" & _
" SELECT '" & .Fields(0) & "','" & .Fields(1) & "','" & Replace(RTrim(.Fields(2)),
You should also check if the strContactName is not null terminated.
Have you tried assigning your SQL statement to a variable first and debug.print it or examine it's value before executing it?
Those dynamic SQL strings are often a source of error for me, at least. I like to check the string with the actual values in. Unexpected values from ".Replace(RTrim(.Fields(2)
It might help if you expand the code snippet you posted, showing the "set rsImportProcess = " line and the derivation of contactname.
As the previous respondents have suggested, it is necessary to double all single quotes in string values in SQL strings.
I use a "sqlEncode(input as string) as string" function in my databases to prepare each text value that could conceivably contain a single quote. It's a one liner as the previous respondents have suggested replace(input,"'"."''").
Business Accounts
Answer for Membership
by: pcelbaPosted on 2009-11-03 at 15:41:52ID: 25735122
You have to double all apostrophs in the text. Replace function is OK for that:
Select allOpen in new window