An apostophe and a single quote mark are the same thing on a computer keyboard. Since it’s like that, when you create, say, an Insert SQL statement, that contains a an apostrophe, it causes an error. That’s because, when you use an Insert SQL statement, it uses the following syntax:
MySQL=”Insert into TABLEName (Fname, Lname, Address) VALUES (‘” & strFname & “‘, ” & “‘” & strLname & “‘, ” & “‘” & strAddress & “‘”)”
As you can see, the SQL statement uses single quotes around each variable name, so that really messes up the statement when it’s executing. The INSERT statement will think your apostrophe is the end of a string of data, which messes up the rest of the statement.
In order to get around this problem, you can double the single quotes – when SQL encounters two single quotes in a row, it sees them into a single quote.
Here’s a sub you can use to take care of this:
Sub FixQuotes(var)
var = Replace(var, “‘”, “””)
End Sub
Then, before your variable gets into the INSERT statement, you can fix the single quote situation like this:
FixQuotes(strFname)
FixQuotes(strLname)