Handeling Apostrophes in a string expression

  • Thread starter Thread starter LisaB
  • Start date Start date
L

LisaB

Can anyone please tell me how to fix this so that when the word "Women's
Treatment" is the name of the ProgramArea the following code works?

-------------------------------------
If Me.ProgramArea = "Women's Treatment" Then
PArea = "Women" & "'" & "s Treatment" & "'"
Else
PArea = Me.ProgramArea
End If

stLinkCriteria = "[ProgramArea]=" & "'" & PArea & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Simplist way is to replace the apostrophe in your Criteria string with TWO
quotes:

stLinkCriteria = "[ProgramArea]=" & """" & PArea & """"
 
Thank you.

Stewart Tanner said:
Lisa,

try this, without the if then else block.

stLinkCriteria = "[ProgramArea]=" & chr(34) & PArea & chr(34)
DoCmd.OpenForm stDocName, , , stLinkCriteria

there is a great explanation of this at
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=230516



LisaB said:
Can anyone please tell me how to fix this so that when the word "Women's
Treatment" is the name of the ProgramArea the following code works?

-------------------------------------
If Me.ProgramArea = "Women's Treatment" Then
PArea = "Women" & "'" & "s Treatment" & "'"
Else
PArea = Me.ProgramArea
End If

stLinkCriteria = "[ProgramArea]=" & "'" & PArea & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
------------------------------------

I get the following error message
Syntax error (missing operator) in query expression '[ProgramArea] =
'Women's Treatment'"
 
Thank You.

Roger Carlson said:
Simplist way is to replace the apostrophe in your Criteria string with TWO
quotes:

stLinkCriteria = "[ProgramArea]=" & """" & PArea & """"


--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org


LisaB said:
Can anyone please tell me how to fix this so that when the word "Women's
Treatment" is the name of the ProgramArea the following code works?

-------------------------------------
If Me.ProgramArea = "Women's Treatment" Then
PArea = "Women" & "'" & "s Treatment" & "'"
Else
PArea = Me.ProgramArea
End If

stLinkCriteria = "[ProgramArea]=" & "'" & PArea & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
------------------------------------

I get the following error message
Syntax error (missing operator) in query expression '[ProgramArea] =
'Women's Treatment'"
 
Back
Top