By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 3,102 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

syntax error message for names with apostrophe

P: 1
Hi,

i'm getting syntax error message for this button that tries to get name (of building) with apostrophe. Any idea how to solve this? Note that i must use name with apostrophe e.g. O'neal:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command76_Click()
  2. On Error GoTo Err_Command76_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = ChrW(1506) & ChrW(1491) & ChrW(1499) & ChrW(1503) & ChrW(32) & ChrW(1508) & ChrW(1512) & ChrW(1496) & ChrW(1497) & ChrW(32) & ChrW(1502) & ChrW(1489) & ChrW(1504) & ChrW(1492)
  8.  
  9.     stLinkCriteria = "[Building]=" & "'" & Me![Building] & "'"
  10.     DoCmd.OpenForm stDocName, , , stLinkCriteria
May 4 '10 #1

✓ answered by MikeTheBike

@inbarik
Hi

You could try ths

stLinkCriteria = "[Building]=" & "'" & Replace(Me![Building],"'","''") & "'"

This will replace all occurrences of a single apostrophe in the Building string with 2 apostophes.

The interpreter will then assume you want to have a (single) apostrophe in the string and that it is not the end of variable delimiter.

HTH


MTB

Share this Question
Share on Google+
1 Reply


Expert 100+
P: 634
@inbarik
Hi

You could try ths

stLinkCriteria = "[Building]=" & "'" & Replace(Me![Building],"'","''") & "'"

This will replace all occurrences of a single apostrophe in the Building string with 2 apostophes.

The interpreter will then assume you want to have a (single) apostrophe in the string and that it is not the end of variable delimiter.

HTH


MTB
May 4 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.