|
Question : Single quotation in strVariable causes error 2147217900
|
|
Hello, I'm trying to insert a string variable into a table using the following sql statement: Everything works fine until the strVariable contains a single quotation (e.g. Joe's Trucking) in which case I get Error code 2147217900 Syntax error (missing operator) in query expression.
sSQL = "INSERT INTO Vendor (IsActive, Name, CompanyName) " & _ "VALUES (1,'" & strVendorName & "','" & strVendorName & "')"
I'm using VBA within Access 2000
|
|
Answer : Single quotation in strVariable causes error 2147217900
|
|
Use the replace function...something like this:
sSQL = "INSERT INTO Vendor (IsActive, Name, CompanyName) " & _ "VALUES (1,'" & Replace(strVendorName, "'", "''") & "','" & Replace(strVendorName, "'", "''") & "')"
|
|
|
|