This documentation is archived and is not being maintained.

# OnError Macro Action

Office 2007

You can use the OnError action to specify what should happen when an error occurs in a macro.

## Setting

The OnError action has the following arguments.

Action argument Description
Go to Specify the general behavior that should occur when an error is encountered. Click the drop-down arrow and then click one of the following settings:
SettingDescription
NextMicrosoft Office Access 2007 records the details of the error in the MacroError object but does not stop the macro. The macro continues with the next action.
Macro NameAccess stops the current macro and runs the macro that is named in the Macro Name argument.
FailAccess stops the current macro and displays an error message.
Setting Description
Next Microsoft Office Access 2007 records the details of the error in the MacroError object but does not stop the macro. The macro continues with the next action.
Macro Name Access stops the current macro and runs the macro that is named in the Macro Name argument.
Fail Access stops the current macro and displays an error message.
Macro Name If the Go to argument is set to Macro Name, type the name of the macro to be used for error handling. The name you type must match a name in the Macro Name column of the current macro; you can't enter the name of a different macro object. In the example below, the ErrorHandler macro is contained in the same macro object as the OnError action.

This argument must be left blank if the Go to argument is set to Next or Fail.

## Remarks

• The OnError action is usually placed at the beginning of a macro, but you can also place the action later in the macro. The rules established by the action will take effect whenever the action is run.
• If you set the Go to argument to Fail, Access behaves the same way it would if there were no OnError action in the macro. That is, if an error is encountered, Access stops the macro and displays a standard error message. The main use for the Fail setting is to turn off any error handling that you established earlier in a macro.

## Example

The following macro demonstrates the use of the OnError action. In this example, the OnError action specifies that Access run a custom error handling macro named ErrorHandler when an error occurs. If an error occurs in any of the actions that follow, Access jumps to the ErrorHandler macro. The ErrorHandler macro displays a message box that refers to the MacroError object to display information about the error.

Macro Name Action Arguments
OnError Go to: Macro Name

Macro Name: ErrorHandler

[Action 2]
...
[Action n]
ErrorHandler MsgBox Message: ="Error # " & [MacroError].[Number] & " on " & [MacroError].[ActionName] & " action."

Beep: Yes

Type: None