Error 3075 missing operator in query expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cyd44
    New Member
    • Oct 2011
    • 101

    Error 3075 missing operator in query expression

    Hope someone can help with a query expression. I am trying to open a form from a variable set in another form and have the following query set on button click:-

    Code:
    If Not Me.NewRecord Then
    DoCmd.OpenForm "frmChangeBooking", WhereCondition:="[BookLocation]=" & Me.Room
    End If
    I am getting a missing operator error but the syntax is exactly as shown in Acess 2010 Prigrammers Reference?.

    I have Form A with a combo box to list Rooms and I want to open Form B to show records for the Room chosen by Form A. Have captured Me. Variable and this is fine.
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    The parameters to OpenForm in previous versions of Access are
    (Form Name,
    View Mode,
    Filter Name,
    Where Condition,
    Form Mode,
    Window Mode,
    Open Args)

    with everything but Form Name being optional. So I think you need at least one more comma after your form name; I'm not sure if "WhereCondition :=" is specifying the filter name or where condition, I suppose the latter, in which case you need 2 more commas inserted after form name.

    Is "WhereCondition :=" actually part of the call? It doesn't look like any FormOpen I have ever done, but I have not been in Access 2010 yet. I would drop that literal and just put the condition itself.

    Jim

    Comment

    • Cyd44
      New Member
      • Oct 2011
      • 101

      #3
      Hi jimatqsi

      many thanks for the advise, I have managed to get this working by reverting to a query and calling the Filtername argument
      Code:
      If Not Me.NewRecord Then
      DoCmd.OpenForm "frmChangeBooking", FilterName:="qryShowbookingbyRoom"
      
      End If
      However, I looked at Context sensiteve Help for WhereCondition and it gives an example exactly how I had coded it originally. This example does not work for me.

      Not to worry, I have got it working using Filtername.

      many thanks for your advise and comments

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32653

        #4
        I cannot say positively what your problem was Cyd, but it wasn't the use of WhereCondition=. That's an example of named parameters and, though it's more typical to use all names in a call, it is possible to use named parameters after some positional ones. It's not possible to use any positional ones after a named one has been used. With named parameters the number of commas (,) is irrelevant.

        I'm guessing the parameter passed included reference to a string value. If [BookLocation] is a string rather than a number then the code should have been :
        Code:
        If Not Me.NewRecord Then
            DoCmd.OpenForm "frmChangeBooking", WhereCondition:="[BookLocation]='" & Me.Room & "'"
        End If
        Of course, using FormName:="frmC hangeBooking" would be even better and easier to read.

        PS. I just reset the Best Answer as it was more of a question than an answer - and not really very near the mark on this one I'm afraid Jim.

        Comment

        • jimatqsi
          Moderator Top Contributor
          • Oct 2006
          • 1293

          #5
          You're absolutely right, Ade. I have never seen passing parameters like that. I swear, after 10 years I still learn something new about Access nearly every day.

          Thank you for your post, Cyd44, and for your illumination of this subject, NeoPa.

          Jim

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32653

            #6
            I won't say it was a pleasure, as resetting another expert's answer is something I don't like to do, but if it helped illuminate this point then I'm certainly happier than I was ;-)

            I always hated the idea of positional parameters with optionals missed out. Multiple commas seem to me a very poor, and easily confused, way of passing parameters. Named parameters can be cumbersome, so I don't use them all the time, but for when a call is obscure I like to use them. It adds clarity to the code I find.

            Comment

            • Cyd44
              New Member
              • Oct 2011
              • 101

              #7
              Thanks a lot guys. In the end I used a query to open the form by setting OpenForm "form" Filter = query

              This works fine.

              Thanks again guys

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32653

                #8
                That will work for you Cyd, but I'd recommend you use the WhereCondition approach going forward where possible.

                Maintaining queries simply for handling something easily handled by a string in your code gives you extra work, leaves more disparate items in your database to maintain and is even less clear to understand when someone has to review or debug the project. It is also a more standard approach so whenever working with others (EG asking questions here on Bytes or discussing with a colleague) you are more likely to reach a common understanding and find communication easier (This translates to more experts who are able to help with a question).

                Comment

                Working...