By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,611 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,611 IT Pros & Developers. It's quick & easy.

Error 3075 missing operator in query expression

100+
P: 101
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:-

Expand|Select|Wrap|Line Numbers
  1. If Not Me.NewRecord Then
  2. DoCmd.OpenForm "frmChangeBooking", WhereCondition:="[BookLocation]=" & Me.Room
  3. End If
  4.  
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.
Nov 4 '11 #1
Share this Question
Share on Google+
7 Replies


Expert 100+
P: 1,221
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
Nov 4 '11 #2

100+
P: 101
Hi jimatqsi

many thanks for the advise, I have managed to get this working by reverting to a query and calling the Filtername argument
Expand|Select|Wrap|Line Numbers
  1. If Not Me.NewRecord Then
  2. DoCmd.OpenForm "frmChangeBooking", FilterName:="qryShowbookingbyRoom"
  3.  
  4. 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
Nov 4 '11 #3

NeoPa
Expert Mod 15k+
P: 31,712
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 :
Expand|Select|Wrap|Line Numbers
  1. If Not Me.NewRecord Then
  2.     DoCmd.OpenForm "frmChangeBooking", WhereCondition:="[BookLocation]='" & Me.Room & "'"
  3. End If
Of course, using FormName:="frmChangeBooking" 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.
Nov 11 '11 #4

Expert 100+
P: 1,221
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
Nov 12 '11 #5

NeoPa
Expert Mod 15k+
P: 31,712
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.
Nov 12 '11 #6

100+
P: 101
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
Nov 14 '11 #7

NeoPa
Expert Mod 15k+
P: 31,712
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).
Nov 14 '11 #8

Post your reply

Sign in to post your reply or Sign up for a free account.