can a macro be stopped in code?

E

everymn

I'm running a bunch of code from the autoexec macro in sequence,
however if the first function fails I need to be able to stop the
whole thing from running. Is there a way from a within a VB function
to be able to stop the macro which called it?

Thank You
 
D

Douglas J. Steele

Lack of error trapping is one of the reasons why many people don't use
macros.

Unless there's some way that you can tell in advance that it's going to fail
(so that you don't bother running that code), you may need to move to VBA,
which does have error trapping.
 
E

everymn

On Fri, 15 Dec 2006 05:52:06 -0500, "Douglas J. Steele"

Yes I was afraid of this. If I can't halt execution of the macro from
VB, is there a way I can completely exit the program before the errors
start cascading?
Thanks
 
S

Steve Schapel

Everymn,

1. You could re-write the VBA code so that the error does not occur.
2. You could use error handling code within your VBA procedure(s) to
quit the application in the case of an error.
3. You could forget the idea of an AutoExec macro, and instead write
your VBA procedure on the Open event of a startup form.
 
D

Douglas J. Steele

3b. You could have your AutoExec macro call a VBA function you've stored in
a module.
 
S

Steve Schapel

That's what I assumed was already the case, Doug, i.e. that was the
starting point for Everymn's question...
 
D

Douglas J. Steele

Yes and no. I read it as the macro called function1, then called function2,
then called function 3.

While I realize I didn't spell it out in detail, I'm suggesting that the
macro only call function1, and that function1 take care of calling all the
other functions, since it's capable of using error trapping to know when to
stop if necessary.
 
E

everymn

On Sat, 16 Dec 2006 07:09:23 -0500, "Douglas J. Steele"


Douglas,
Correct, I'm calling procs in sequence from the macro. The object is
to make it usable for non programmer types so I'm treating autoexec
like a console.

I elected to check all the variables up front in the first proc and
then throw up a warning and docmd.exit if all is not well.
Thanks
Eric
 

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