Apostrophe in variable

  • Thread starter Thread starter SAC
  • Start date Start date
S

SAC

I'm trying to do this:

txtTaxes = IIf([State] = "KS", [txtPriceEa] * DLookup
("CityRate", "tblTaxAuthoritiesNew", "[City] = " & rsCust!City & """), 0)

rsCust!City has an apostrophe in it. How do I handle this?

Thanks.
 
Use double quotes instead of the single quote character to delimit the city
name within the string:
"[City] = """ & rsCust!City & """"

Where you want the double-quote character inside a string, you need to
double it so that VBA understands this is not the end of the string. For
example, to get:
This string has a "word" in quotes
you code:
"This string has a ""word"" in quotes"
 
Thanks!


Allen Browne said:
Use double quotes instead of the single quote character to delimit the city
name within the string:
"[City] = """ & rsCust!City & """"

Where you want the double-quote character inside a string, you need to
double it so that VBA understands this is not the end of the string. For
example, to get:
This string has a "word" in quotes
you code:
"This string has a ""word"" in quotes"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

SAC said:
I'm trying to do this:

txtTaxes = IIf([State] = "KS", [txtPriceEa] * DLookup
("CityRate", "tblTaxAuthoritiesNew", "[City] = " & rsCust!City & """), 0)

rsCust!City has an apostrophe in it. How do I handle this?
 
Back
Top