Double & Single quotation marks issues (1 Viewer)

FuzMic

DataBase Tinker
Local time
Today, 11:41
Joined
Sep 13, 2006
Messages
719
Hi gals / guys

I use the following to append in a table, Tbl1
"INSERT INTO Tbl1 ( Txt ) SELECT '" & Var1$ & "' AS Cs;"

As you can see the Var1$ as a string. In the query there it is quoted with a single quote before a double quote.

The issue: if var1$ also contain a single quote eg House's flies, then append query will no execute.

Any suggestion to solve this. My current way is to avoid any single quote in the Var1$, not so smart.
 

June7

AWF VIP
Local time
Yesterday, 19:41
Joined
Mar 9, 2014
Messages
5,466
Have to 'escape' the special character. This is accomplished by doubling the character. I use Replace function to handle this:

Replace(Var1$, "'", "''")

You don't need the SELECT if you don't specify a table with FROM. I don't see how this can work anyway without FROM clause.

"INSERT INTO Tbl1 ( Txt ) VALUES('" & Replace(Var1$, "'", "''") & "'"
 

FuzMic

DataBase Tinker
Local time
Today, 11:41
Joined
Sep 13, 2006
Messages
719
Thank you June, i feel it will work. I will try it.

i learn something new about VALUES, thanks for that. Cheer!
 

FuzMic

DataBase Tinker
Local time
Today, 11:41
Joined
Sep 13, 2006
Messages
719
June

the Replace works out but

VALUES part flag syntax error, any reason
 

June7

AWF VIP
Local time
Yesterday, 19:41
Joined
Mar 9, 2014
Messages
5,466
Sorry, forgot end ) for the VALUES clause.

& "')"
 

FuzMic

DataBase Tinker
Local time
Today, 11:41
Joined
Sep 13, 2006
Messages
719
Ya I also missed that should work, ��
 

Users who are viewing this thread

Top Bottom