stLinkCriteria with field that has a quote

  • Thread starter Thread starter Lisa
  • Start date Start date
L

Lisa

Hi,

I have surname on a form, and sometimes the surname might have a quote, like
O'Neil. This is my statement to set the criteria, but it does not like the
user entering a quote in the data - how can I fix this?

stLinkCriteria = "[LastName] LIKE '" & Me![surname] & "*'"

Thanks,

Lisa
 
Use the Replace function to double up a ' character within the control's
value string; then ACCESS will correctly interpret it as a single quote:

stLinkCriteria = "[LastName] LIKE '" & _
Replace(Me![surname], "'", "''", 1, -1, vbTextCompare) _
& "*'"
 
Lisa said:
Hi,

I have surname on a form, and sometimes the surname might have a quote,
like
O'Neil. This is my statement to set the criteria, but it does not like
the
user entering a quote in the data - how can I fix this?

stLinkCriteria = "[LastName] LIKE '" & Me![surname] & "*'"

Thanks,

Lisa

Presumably you mean a single-quote. All you have to do is double them up in
your criteria string, ie:

stLinkCriteria = "[LastName] LIKE '" & Replace(Me![surname],"'", "''") &
"*'"

That replaces all single quotes with 2 adjacent ones.
 
Back
Top