syntax error message for names with apostrophe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • inbarik
    New Member
    • May 2010
    • 1

    #1

    syntax error message for names with apostrophe

    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:

    Code:
    Private Sub Command76_Click()
    On Error GoTo Err_Command76_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        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)
        
        stLinkCriteria = "[Building]=" & "'" & Me![Building] & "'"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    Last edited by MMcCarthy; Jun 12 '10, 11:38 PM. Reason: Added code tags - see the # icon on posting window
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by inbarik
    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:

    Private Sub Command76_Click ()
    On Error GoTo Err_Command76_C lick

    Dim stDocName As String
    Dim stLinkCriteria As String

    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)

    stLinkCriteria = "[Building]=" & "'" & Me![Building] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    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

    Comment

    Working...