I have answered many questions about syntax errors when trying to query for strings in SQL and VB.
The following is my suggestion if you are having problems:
1) The string you are searching for must always be enclosed in single quotes :
SQL:
SELECT Name from MyTable where Surname = 'Fred'
VB:
mystr = "SELECT Name from MyTable where Surname = 'Fred'"
2) If the string you are searching for Contains a single quote then the single quote must be doubled
SQL:
SELECT Name from MyTable where Surname = 'Fred's'
VB:
mystr = "SELECT Name from MyTable where Surname = 'Fred's'"
3) If you are using variables in VB and the string you are searching for Contains a single quote then the single quote must STILL be doubled. This can be accomplished by writting a VB function that replaces any single quote with two single quotes. The SQL string must still be enclosed in single quotes:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.