macro query cancel causes error

A

Alex Pavluck

I'm using a command button on a form to launch a macro,
which in turn opens a query. That's because I don't see
an option to directly launch a query from a command
button, without the intermediate step of using a macro to
open the query. I imagine launching a query directly from
the button can be done in VBA code but I don't know how.
My problem is this. The query has a built in prompt (text
in brackets under "criteria" in query design view) which
opens a little dialog box that prompts the user to enter
which Order Number to search for in this case.
The query runs fine when opened *directly* without the
intermediate step of using a macro to open the query, in
that I can click on cancel when the dialog box appears,
and the action cancels without an error message.
The query also runs fine from the command button's macro,
with one exception. If you click on cancel when the
dialog box appears prompting for Order Number to search
for, there is an error message window titled "Action
Failed" which pops open.
In the Action Failed window it has the following lines:
MacroName:
macFindOrder
Condition:
True
ActionName:
OpenQuery
Arguments:
qryFindOrder, Datasheet, Edit
 
S

Steve Schapel

Alex,

As far as I know, there is no way to prevent this. Well, apart from not
click the button unless you intend to see the process through... I mean,
why are you cancelling out anyway?
 
A

Alex Pavluck

Well, that's not good. Why am I cancelling? I guess the reason is
because there are multiple choices and if you launch one and you ment
to use another then you would cancel your current query. I am shocked
that a microsoft product would not make this easy. Oh, well.
 
S

Steve Schapel

Alex,

If the user is so prone to always click the wrong button, the
alternative is to use a VBA procedure instead of a macro, in which case
it will allow to trap the error.

Another approach is to put an unbound textbox on a form for the entry of
the criteria, in this case the required Order Number, instead of the
Parameter Query approach. You would then refer to the textbox in the
query criteria, in the place of the existing parameter prompt, using
syntax such as [Forms]![NameOfForm]![NameOfTextbox]. In over 10 years
as a professional Access developer, I have personally never used a
parameter query.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top