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

O'Hare - problem with last name 2

Status
Not open for further replies.

andzejek

MIS
Sep 1, 2007
154
US
here is the code:

Dim str_Last_Name as string

SQLstr = "Insert into Customer ([LAST_NAME]) Values('" & str_Last_Name & "');"

It is working fine but not for names like O'Hare. Can someone help me with that?
 
You need to replace every single apostrophe ' with two apostrophes.

Code:
Dim str_Last_Name as string

str_last_name = Replace (str_last_name, "'", "''")

SQLstr = "Insert into Customer ([LAST_NAME]) Values('" & str_Last_Name & "');"

John
 
The reason is because of the ' .... when you create your query string you end up with:

Code:
INSERT INTO Customer ([LAST NAME]) VALUES ([b]'[/b]O[b]'[/b]Hare[b]'[/b]);

Here's a solution that I found by searching the Access fora for apostrope in name...
Code:
sqlOut = "INSERT INTO tryit (myID) VALUES ('" & Replace(aEMPLID, "'", "''") & "')"

Leslie

Essential for database developers:
The Fundamentals of Relational Database Design
Understanding SQL Joins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top