Stopping the "Action Failed" msg when Autokeys macro interrupted

N

Nat Sci

Hi,

Using Access 2003, I have an Autokeys macro which sets key F10 to shut down
the active form. However on one form I have some code in the Form_Unload
event which can cancel the unload and therefore the close of the form
(depending on certain conditions).

If I use F10 to close the form and the conditions cause the Cancel arguement
of the Unload event to be true, the Form_Unload code runs and then I get the
"Action Failed" dialogue box appearing for the F10 Autokey (with only the
"Halt" button enabled). Is there any way I can stop the "Action Failed"
dialogue box appearing?

I have tried adding SetWarnings commands to the macro, which didn't work. I
have tried a conditional StopMacro command as well, but this then stops the
entire close process, including the Form_Unload event.

I do have a boolean variable available in my Form_Unload code, but I don't
know how to access this from the macro.

Any suggestions greatly appreciated!
 
W

Wolfgang Kais

Hello.

Nat Sci said:
Using Access 2003, I have an Autokeys macro which sets key F10 to
shut down the active form. However on one form I have some code in
the Form_Unload event which can cancel the unload and therefore the
close of the form (depending on certain conditions).

If I use F10 to close the form and the conditions cause the Cancel
arguement of the Unload event to be true, the Form_Unload code runs
and then I get the "Action Failed" dialogue box appearing for the
F10 Autokey (with only the "Halt" button enabled). Is there any way
I can stop the "Action Failed" dialogue box appearing?

Unfortunately, macros can not contain error handling. You will have to
use VBA code for that. Since the AutoKeys functionality can not be
implemented in VBA, you will have to use a combination.
Create a Module and enter a small function, for example this one:

Function CloseActiveWindow()
On Error Resume Next
DoCmd.Close
End Function

This function tries to close the active window and ignores any errors.
Save the module.
Use the RunCode action in you macro to execute this function.
 
N

Nat Sci

Thanks Wolfgang, that gets me unstuck :)

Wolfgang Kais said:
Hello.



Unfortunately, macros can not contain error handling. You will have to
use VBA code for that. Since the AutoKeys functionality can not be
implemented in VBA, you will have to use a combination.
Create a Module and enter a small function, for example this one:

Function CloseActiveWindow()
On Error Resume Next
DoCmd.Close
End Function

This function tries to close the active window and ignores any errors.
Save the module.
Use the RunCode action in you macro to execute this function.
 

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