sql syntax

Posted on 2004-11-16
Medium Priority
Last Modified: 2010-05-02
Can someone give me the correct syntax for inserting a name if the name could possibly contain a '
like Pete D'onofrio ?


insertSQL = "Insert into TABLE1 (F_NAME, L_NAME)
VALUES ('" & rNames![F_NAME] & "',  '" & rNames![L_NAME] & "')"
Insert into TABLE1 (F_NAME, L_NAME)
VALUES ('PETE', 'D'ONOFRIO')  --> causes an error
Question by:cmrka
  • 2
LVL 97

Accepted Solution

Lee W, MVP earned 200 total points
ID: 12592801
For the names, surround them with "Replace" - you can't put an apostrophe (single quote) in a text field in sql - you have to double it.

For example
insertSQL = "Insert into TABLE1 (F_NAME, L_NAME)
VALUES ('" & Replace(rNames![F_NAME], "'", "''") & "',  '" & Replace(rNames![L_NAME], "'", "''") & "')"

This would yeild:
Insert into TABLE1 (F_NAME, L_NAME)

Which should work
LVL 97

Expert Comment

by:Lee W, MVP
ID: 12592804
Your data will only have a single quote mark, but you have to store it using two.

Author Comment

ID: 12592979

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question