• Syntax error (missing operator) (Access 2k)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Syntax error (missing operator) (Access 2k)

    Author
    Topic
    #409646

    Hello All

    I’m trying to use an SQL string in VBA code, but I’m getting the error 3057 Syntax error (missing operator) due to the SQL I’ve entered. It’s going to be something like my date format, but I’ve tried what little I know and it hasn’t worked.

    Here’s my SQL: –

    strWordSQL = “SELECT * FROM PrimaryDataTbl WHERE DateReceived BETWEEN # ” & Me.StartDateTxt & ” # AND # ” & Me.EndDateTxt & ” # VendorNumber = ” & Me.VendorNumber

    I’ve tried it without the # marks around the dates. Added them in the hopes it was as simple as having to put the ‘ before any text items referred to in a SQL string.

    Using the de###### shows me that all three me.statements have the values in, using the SQL in the QBE window (with minor mods to suit the criteria) gives me the results I want……

    Please, help while I still have a little hair left that isn’t either grey or on the desk hairout

    Thanks

    Ian

    Viewing 5 reply threads
    Author
    Replies
    • #874605

      Have you got a space after the first # and before the second # ? ie. # ” and ” #

      If so it will be looking for # 01/09/2004 # rather than #01/09/2004#

    • #874606

      Have you got a space after the first # and before the second # ? ie. # ” and ” #

      If so it will be looking for # 01/09/2004 # rather than #01/09/2004#

    • #874607

      What if you use :
      strWordSQL = “SELECT * FROM PrimaryDataTbl WHERE DateReceived BETWEEN # ” & Me.StartDateTxt & ” # AND # ” & Me.EndDateTxt & ” # And VendorNumber = ” & Me.VendorNumber

    • #874608

      What if you use :
      strWordSQL = “SELECT * FROM PrimaryDataTbl WHERE DateReceived BETWEEN # ” & Me.StartDateTxt & ” # AND # ” & Me.EndDateTxt & ” # And VendorNumber = ” & Me.VendorNumber

    • #874698

      Ian,

      Is VendorNumber = ” & Me.VendorNumber part of your strWordSQL statement? Also, Does the strWordSQL statement wrap as shown in your post or is it on one line?

      If wrapping the strSql string, then you would need something like this

      strWordSql = “Select * From” _
      & ” SomeTable;”

      You will also need to add an ; at the end of your statement, for example,
      strWordSql = “Select * from SomeTable;”

      • #874702

        Francois

        As yet I don’t what’s different between your SQL string and mine, but whatever it is it works hailpraise another learning opportunity provided by the good folks of Woody’s lounge

        cheers

        Thanks

        Ian

        • #874706

          You forget the And before VendorNumber.
          Between two conditions you have an AND or an OR.
          Gald it work for you now.

        • #874707

          You forget the And before VendorNumber.
          Between two conditions you have an AND or an OR.
          Gald it work for you now.

      • #874703

        Francois

        As yet I don’t what’s different between your SQL string and mine, but whatever it is it works hailpraise another learning opportunity provided by the good folks of Woody’s lounge

        cheers

        Thanks

        Ian

    • #874699

      Ian,

      Is VendorNumber = ” & Me.VendorNumber part of your strWordSQL statement? Also, Does the strWordSQL statement wrap as shown in your post or is it on one line?

      If wrapping the strSql string, then you would need something like this

      strWordSql = “Select * From” _
      & ” SomeTable;”

      You will also need to add an ; at the end of your statement, for example,
      strWordSql = “Select * from SomeTable;”

    Viewing 5 reply threads
    Reply To: Syntax error (missing operator) (Access 2k)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: