MS ACCESS, Syntax error (missing operator)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Richardson
    New Member
    • Sep 2007
    • 8

    MS ACCESS, Syntax error (missing operator)

    Hi to everyone,

    I have the following problem which is producing the following error:

    Syntax error (missing operator) in query expression '(CourseNo = CN1863)

    This caused from the follOwing being run from a command button on a form. The sync is between the form (Combo box ) and a report (txt field).

    DoCmd.OpenRepor t "RptValidationM ainP3_Course186 3", acPrintPreview, , "CourseNo = " & Me.CourseNo

    The report is based on a table which has many 'CourseNo's', and I want the chosen value from the form combo to filter the records to be printed in the report. i.e select CourseNo '1863' via the combo box on the form (with other fields input by the user) and then clicking the command button opens the report filtered to the combo box value.

    My apologies if i've been a bit long winded describing this, and hope that there is enough here to show my problem.

    Any assistance would be really appreciated.

    My Thanks

    Dave
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Originally posted by Dave Richardson
    ...I have the following problem which is producing the following error:
    Syntax error (missing operator) in query expression '(CourseNo = CN1863)
    ...
    DoCmd.OpenRepor t "RptValidationM ainP3_Course186 3", acPrintPreview, , "CourseNo = " & Me.CourseNo
    Hi Dave. This problem crops up fairly frequently in referring to string values, and arises because you are missing two quote marks from the filter statement. This should be:
    Code:
    DoCmd.OpenReport "RptValidationMainP3_Course1863", acPrintPreview, , "CourseNo = '" & Me.CourseNo & "'"
    Without the quote marks Access is trying to interpret the course name as a field name or operator, without success.

    Add the quote marks in as shown and the DoCmd should be OK.

    -Stewart

    Comment

    • Dave Richardson
      New Member
      • Sep 2007
      • 8

      #3
      Originally posted by Stewart Ross Inverness
      Hi Dave. This problem crops up fairly frequently in referring to string values, and arises because you are missing two quote marks from the filter statement. This should be:
      Code:
      DoCmd.OpenReport "RptValidationMainP3_Course1863", acPrintPreview, , "CourseNo = '" & Me.CourseNo & "'"
      Without the quote marks Access is trying to interpret the course name as a field name or operator, without success.

      Add the quote marks in as shown and the DoCmd should be OK.

      -Stewart

      Hi Stewart,

      Works a treat!. This is one thing i will pop in my good gen folder. Many many thanks, and I am smiling like a 3 year old kid!!

      with best wishes, Dave

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        Originally posted by Dave Richardson
        Hi Stewart,

        Works a treat!. This is one thing i will pop in my good gen folder. Many many thanks, and I am smiling like a 3 year old kid!!

        with best wishes, Dave
        Very glad to have been able to help, Dave.

        Regards

        Stewart
        Last edited by Stewart Ross; Mar 3 '08, 10:17 AM. Reason: typo

        Comment

        • jghouse
          New Member
          • Jul 2008
          • 9

          #5
          I was running into this same problem and it turned out that I was missing the quotation marks as susggested. This got me past that hurdle however I know have a new problem.

          Now when I go to open the report I am present with a message box asking me to input the value that is referenced in the filter.

          Anyone with ideas?

          Comment

          • Stewart Ross
            Recognized Expert Moderator Specialist
            • Feb 2008
            • 2545

            #6
            Hi jghouse. We'd need to know a bit more about your problem before we can answer it, and as it really does not relate to this particular thread it would be better to start a new discussion thread for your current difficulty.

            If you could please do so, posting the code that is used to open your report, it would be much appreciated.

            Thanks

            Stewart

            Originally posted by jghouse
            ...Now when I go to open the report I am present with a message box asking me to input the value that is referenced in the filter.

            Comment

            • jghouse
              New Member
              • Jul 2008
              • 9

              #7
              Originally posted by Stewart Ross Inverness
              Hi jghouse. We'd need to know a bit more about your problem before we can answer it, and as it really does not relate to this particular thread it would be better to start a new discussion thread for your current difficulty.

              If you could please do so, posting the code that is used to open your report, it would be much appreciated.

              Thanks

              Stewart
              Stewart,

              Thanks to your attention on this. After a night away from it I realized an unbelievably stupid error. My issue is not fixed but this thread was helpful in oslving my original one. Thanks again for all you do.

              Comment

              Working...