Stopping a macro from a custom dialog box

G

Guest

I have created a custom dialog box and have connected it to a group macro
with an open, close, cancel and so forth button within the group macro. The
custom dialog box has an OK button and a Cancel button. All works well with
the OK button, but the Cancel button will close the dialog box but any
queries and so forth keep running and of course fail because of the missing
data. How do I get the query and everything else to stop running. I have
tried the Stop Macro and the StopAllMacros in the action window of the macros
but this does not work. The macro continues through the queries and all.

Please help!!!

Regards,

Rob
 
A

Allen Browne

To conditionally stop the macro, you need an expression in the Macro
Conditions column, and the expression needs to return True (to stop the
macro) or False (to let it keep running.) This goes on the line where you
have the StopMacro action.

To implement such a condition, you create a function (code) that returns the
True or False. You need a global boolean variable that your custom dialog
can set to True or False. The function will open your custom dialog modally,
the custom dialog will set the boolean, and the function will then return
the True or False value.

If you don't need the custom dialog, you could just use MsgBox() in the
Macro Conditions column, e.g.:
MsgBox("Proceed?", 33, "Please confirm") = 2
That expression is True if the person clicks the Cancel button in the
dialog, so when it is True, Access does the StopMacro for you.

If you are running a series of action queries where you need to know that
the first one worked before the next one runs, you really need to Execute
the action queries in code so you can determine whether they worked rather
than rely on the user to read all the dialogs and answer them correctly. For
instructions on how to do that, see:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html
 
G

Guest

Allen, thanks for the response but I don't understand the details of the
Visual Basic coding. I have created fairly sophisticated databases using the
interface but have not needed to do much actual coding. I have a module that
I copied from the Northwind database for the Not isLoaded condidtion and and
I use this in the Open Dialog Form area of the group macro. Can you please
write the condition necessary to stop all further actions at the cancel
level.

Rob







I really appreciate your help.

Rob
 
A

Allen Browne

If you want to stop the macro if Form1 is not loaded, put this in the Macro
Conditions column:
Not IsLoaded("Form1")
beside StopMacro in the Action column.
 

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