Quotation marks in string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I open up a table and then do a search for the first record that matches a
string expression. Unfortunately, if the string contains a quotation mark,
e.g., Tubing, 8", I get a data type mismatch error. It's obvious why this is
happening inasmuch as double quotes are used in my code to desiginate the
text:

rec.FindFirst "Description = '" & strDescription & "'"

Any one know what I need to do? Thanks.

Ken
 
I open up a table and then do a search for the first record that matches a
string expression. Unfortunately, if the string contains a quotation mark,
e.g., Tubing, 8", I get a data type mismatch error. It's obvious why this is
happening inasmuch as double quotes are used in my code to desiginate the
text:

rec.FindFirst "Description = '" & strDescription & "'"

Any one know what I need to do? Thanks.

Ken

Hrm. Actually that particular FindFirst syntax should work correctly
with strDescriptions containing " but will fail when they contain an
apostrophe ', since you're delimiting with '; with your example this
criterion would evaluate to

Description = 'Tubing, 8"'

which should work.

You can double up the singlequotes in a string delimited by
singlequotes: try

rec.FindFirst "Description = '" & Replace(strDescription, "'", "''") &
"'"

John W. Vinson[MVP]
 
Back
Top