View Full Version : OpenForm macro ... WHERE statement error


grjhit
10-03-2004, 02:07 PM
HI! I have succeeded where others seem to have problems;

I have created a list box with buttons in a form
They open other forms related to both simple queries or crosstab queries filtering the information as I need them.

The Where statement contains a discrete value i.e. [name]="Jones"

However, on one of the openform statements I have put a variable related to a combo box on my main form in the WHERE statement;

WHERE [name]=[Forms]![Input form]![surname]

This works great for opening a form based on a simple query. BUT when I try a similar statement to open a form based on a crosstab query I have an error;

The microsoft Jet database does not recognize '[Forms]![Input form]![surname]' as a valid field name or expression.

This works perfectly on a form based on a simple query and if I change the variable back to a discrete value for the crosstab related form there is no problem.

ANY IDEAS????

pbaldy
10-03-2004, 10:07 PM
Crosstabs must have their parameters explicitly declared. It's been discussed many times here, including this one:

http://www.access-programmers.co.uk/forums/showthread.php?t=61142

grjhit
10-03-2004, 10:29 PM
Thanks for that. Now that function works perfectly for selecting the name in the combobox.

The problem now is that when I don't pass that variable. For example;

in the button list;
button1 : country = "France"
button 2: country ="UK"
button 3: name="Jones"

Button 3 works, but button 1 and 2 used to work, but now they run the query, show the results and then all the results dissappear showing the blank query.

pbaldy
10-04-2004, 09:04 AM
Can you post a sample db?

grjhit
10-04-2004, 01:33 PM
OK .. u r right!!!

It seems that once you screw up on a macro and try and run it (values are wrong or something like that) Access remembers u were wrong.

Re-wrote the db and it works!!! THANKS!

BUT! Now I face the problem that something was wrong on another button. The macro didn't work right first time round and it gave me an error. Now I have corrected the problem but the memory of an error is still there, (The problem I had this morning when I tried your solution first time). Do I have to re-create the db everytime so that it forgets the error?

pbaldy
10-04-2004, 02:23 PM
I have to admit that I never use macros, so I'm not familiar with this problem. Is the macro getting saved with bad criteria or something? I can't imagine that you'd have to recreate the db; maybe the macro itself at worst, but not the whole thing.

If you can't post a sample db, what exactly is the macro doing?

grjhit
10-13-2004, 10:46 PM
Sorry for the late reply. I have now found out that it wasn't a problem of the macro but a problem of the Form. All is working OK now. Thanks for your help!