Yes, because, in a similar way to Pascal, two single quotes in a row is interpreted as one single quote contained within a string.
I just thought maybe that could do with explaining.
Printable View
Yes, because, in a similar way to Pascal, two single quotes in a row is interpreted as one single quote contained within a string.
I just thought maybe that could do with explaining.
That worked. Thanks for the help.
Does anyone have a work around for handling strings containing apostrophies that are being passed into a SQL statement?
Example. I have form with a textbox for Last Name, First Name and Phone Number. If the lastname box contains something like O'Hara I get a syntax error when I try to run
"INSERT INTO contacts (lastname, firstname, phone) VALUES ('" & txtLastname.text & "', '" & txtFirstname.text & "', '" & txtPhone.text & "'). The apostrophy in O'Hara is being confused with the tick in my SQL statement. I am using an Access database.
Any help would be appreciated.
you can use the VB6 REPLACE function to find those single quotes and convert them to double single quotes...
HTHCode:
dim strSQL as string
strSQL = "Select * from Customers where CustomerID = '" & replace(text1.text, "'", "''") & "'"
Tom