Syntax Error (missing operator) in query expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lumpierbritches

    Syntax Error (missing operator) in query expression

    Syntax Error (missing operator) in query expression [AnimalID]=BLANK'S
    MOLLIE-PRINCE BRUISER-3/14/2004-03

    AnimalID is correct. I'm trying to open with a command button or double click
    the frmAnimal from a subform that uses the same table, is that my problem?

    If I remove the criteria from the expression, it opens the form, but to show
    every record.


    Michael
  • Bob Quintal

    #2
    Re: Syntax Error (missing operator) in query expression

    lumpierbritches @aol.com (Lumpierbritche s) wrote in
    news:2004042618 5459.17730.0000 0439@mb-m16.aol.com:
    [color=blue]
    > Syntax Error (missing operator) in query expression
    > [AnimalID]=BLANK'S MOLLIE-PRINCE BRUISER-3/14/2004-03
    >
    > AnimalID is correct. I'm trying to open with a command button
    > or double click the frmAnimal from a subform that uses the
    > same table, is that my problem?
    >
    > If I remove the criteria from the expression, it opens the
    > form, but to show every record.
    >
    >
    > Michael
    >[/color]

    Iwhat you need to see is
    [AnimalID]="BLANK'S MOLLIE-PRINCE BRUISER-3/14/2004-03"

    review the location in the button's OnClick event to add extra
    quotes. If you can't figure it out, post the relevant sections of
    code.

    Bob Quintal

    Comment

    • Lumpierbritches

      #3
      Re: Syntax Error (missing operator) in query expression

      Private Sub cmdOpenAnimal_C lick()
      On Error GoTo Err_cmdOpenAnim al_Click

      Dim stDocName As String
      Dim stLinkCriteria As String

      stDocName = "frmAnimal"

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

      Exit_cmdOpenAni mal_Click:
      Exit Sub

      Err_cmdOpenAnim al_Click:
      MsgBox err.Description
      Resume Exit_cmdOpenAni mal_Click

      End Sub

      Comment

      • fredg

        #4
        Re: Syntax Error (missing operator) in query expression

        On 27 Apr 2004 00:12:01 GMT, Lumpierbritches wrote:
        [color=blue]
        > Private Sub cmdOpenAnimal_C lick()
        > On Error GoTo Err_cmdOpenAnim al_Click
        >
        > Dim stDocName As String
        > Dim stLinkCriteria As String
        >
        > stDocName = "frmAnimal"
        >
        > stLinkCriteria = "[AnimalID]=" & "'" & Me![AnimalID] & "'"
        > DoCmd.OpenForm stDocName, , , stLinkCriteria
        >
        > Exit_cmdOpenAni mal_Click:
        > Exit Sub
        >
        > Err_cmdOpenAnim al_Click:
        > MsgBox err.Description
        > Resume Exit_cmdOpenAni mal_Click
        >
        > End Sub[/color]

        Your problem is you have a single quote in the criteria field....

        [AnimalID]=BLANK'S MOLLIE-PRINCE BRUISER-3/14/2004-03

        So your Where clause is failing when it hits the ' in Blank's.

        Try it this way (instead of using & "'" etc.)

        stLinkCriteria = "[AnimalID]=" & chr(34) & Me![AnimalID] & chr(34)

        --
        Fred
        Please only reply to this newsgroup.
        I do not reply to personal email.

        Comment

        Working...