Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002

    Unanswered: Form linking syntax error (use of apostrophe)

    I am using the field "CompanyName" as a link between two forms. This has worked perfectly until I came accross a company with an apostrophe in the name. Access thinks the apostrophe in the name of the company is part of the syntax of the openform command. I have easily worked around the problem by using a unique company ID instead of name to link, but I was just wondering if it was possible to fix the problem so I can use companyname again.

    The error message recieved when the openform command is run is:
    Syntax error (missing operator) in query expression '[CompanyName]='ategic's company".

    I have had similar problem when working with fields titled with "#" or other special characters. Any thoughts on possible workarounds would be greatly appreciated.


  2. #2
    Join Date
    Oct 2001
    Here's a function:

    '[CompanyName]=" & "'" & FixSingleQuotes(Me!CompanyName) & "'"

    Public Function FixSingleQuotes(strIn As String) As String
    ' Double single quotes in a string. Not fast, but doesn't get used
    ' very often
    Dim intI As Integer
    Dim strTemp As String
    Dim strCh As String
    For intI = 1 To Len(strIn)
    strCh = Mid(strIn, intI, 1)
    If strCh = "'" Then
    strTemp = strTemp & "''"
    strTemp = strTemp & strCh
    End If
    Next intI
    FixSingleQuotes = strTemp
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts