Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Dec 2006
    Posts
    250
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Command button to load form (2003)

    Hello,

    I use the wizard to create a command buttom to load up a form. It is link via the granteename. It works great, except when I put one company name "k'MIA:w Center" I get the following error "Syntax error (missing operator) in query expression "[CompanyName]='K'MIA:w Center". Below is the detail of the code.

    Private Sub cmdCompanyNameEditInfo_Click()
    On Error GoTo Err_cmdCompanyNameEditInfo_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmCompanyNameinfo"


    stLinkCriteria = "[CompanyName]=" & "'" & Me![CompanyName] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdCompanyNameEditInfo_Click:
    Exit Sub

    Err_cmdCompanyNameEditInfo_Click:
    MsgBox Err.Description
    Resume Exit_cmdGranteeEditInfo_Click

    End Sub


    Any help would be great. Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Command button to load form (2003)

    This is because you use single quotes ' to delimit the name. The problem name contains a single quote aka apostrophe too, and this confuses Access. To get around this, change the line
    <code>
    stLinkCriteria = "[CompanyName]=" & "'" & Me![CompanyName] & "'"
    </code>
    to
    <code>
    stLinkCriteria = "[CompanyName]=" & Chr(34) & Me![CompanyName] & Chr(34)
    </code>
    See Chr() function and quotes within strings (all) for background information.

Posting Permissions

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