Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ClearMacroError Macro Action

Office 2007

You can use the ClearMacroError action to clear information about an error that is stored in the MacroError object.

Setting

The ClearMacroError action does not have any arguments.

Remarks

  • When an error occurs in a macro, information about the error is stored in the MacroError object. If you have not used the OnError action to suppress error messages, the macro stops and the error information is displayed in a standard error message. However, if you have used the OnError action to suppress error messages, you might want to use the information stored in the MacroError object in a condition or in a custom error message.

    After an error has been handled, the information in the MacroError object is out of date, so it is a good idea to clear the object by using the ClearMacroError action. Doing so resets the error number in the MacroError object to 0 and clears any other information about the error that is stored in the object, such as the error description, macro name, action name, condition, and arguments. This way, you can inspect the MacroError object again later to see if another error has occurred.

  • The MacroError object is automatically cleared when any macro ends, so you do not need to use the ClearMacroError action at the end of a macro.
  • The MacroError object contains information about only one error at a time. If more than one error has occurred in a macro, the MacroError object contains information only about the last error.
  • To run the ClearMacroError action in a VBA module, use the ClearMacroError method of the DoCmd object.

Example

The following macro uses the OnError action with the Next argument to suppress error messages, and then uses the OpenForm action to open a form. For this example, an error is deliberately created by using the GoToRecord action to go to the previous record. The condition [MacroError].[Number]<>0 tests the MacroError object. If an error has occurred, the error number is non-zero, and the MsgBox action runs. The message box displays the name of the action that caused the error (in this case, the GoToRecord action), and the error number is displayed. Finally, running the ClearMacroError action clears the MacroError object.

Condition Action Arguments
OnError Go to: Next
OpenForm Form Name: CategoryForm

View: Form

Window Mode: Normal
GoToRecord Object Type: Form

Object Name: CategoryForm

Record: Previous

[MacroError].[Number]<>0 MsgBox Message: ="Error # " & [MacroError].[Number] & " on " & [MacroError].[ActionName] & " action."

Beep: Yes

Type: Information

ClearMacroError



Show:
© 2014 Microsoft