It looks like you probably used the variable surname as part of a SQL statement. With SQL, the value has to be quoted by ' such as: select * from myTable where name = 'John Smith' If the name value itself contains a ', the SQL statement is invalid: select * from myTable where name = 'John's Smith' What you need to do is replace ' with two consecutive ', like the following: select * from myTable where name = 'John''s Smith' CStr(Replace(Trim(surname), "'", "''")) Good luck.