Sep 12, 2007 #1 andzejek MIS Joined Sep 1, 2007 Messages 154 Location 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?
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?
Sep 12, 2007 1 #2 jrbarnett Programmer Joined Jul 20, 2001 Messages 9,645 Location GB 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 Upvote 0 Downvote
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
Sep 12, 2007 1 #3 lespaul Programmer Joined Feb 4, 2002 Messages 7,083 Location US 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 Upvote 0 Downvote
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
Sep 12, 2007 Thread starter #4 andzejek MIS Joined Sep 1, 2007 Messages 154 Location US Thank you!, it is working now! Upvote 0 Downvote