RaiseError Macro Action

Office 2013 and later

Last modified: July 28, 2015

Applies to: Access 2013 | Office 2013

In this article
Setting
Remarks
Example
About the Contributors

The RaiseError action throws an exception that can be handled by the OnError macro action.

Note Note

The RaiseError action is available only in Data Macros.

The RaiseError action has the following arguments.

Argument

Required

Description

Error Number

Yes

A number or an expression that resolves to the Long data type.

Error Description

No

A string expression that describes the error.

If the RaiseError action is called in a Before Change or Before Delete macro event, the event is cancelled.

If there is not an active OnError statment that is handling errors, then the error thrown by the RaiseError action is added to the USysApplicationLog system table. When the RaiseError action to writes to the USysApplicationLog table, the Category column is automatically set to Execution.

To see the USysApplicationLog table, use the following steps:

  1. Click the File menu, and then click Options.

  2. In the Access Options dialog box, click the Current Database tab.

  3. In the Navigation section, click Navigation Options.

  4. In the Navigation Options dialog box, click Show System Objects, and then click OK.

  5. Click OK to dismiss the Access Options dialog box.

The following example shows how to use the RaiseError action to cancel the Before Change data macro event. When the AssignedTo field is updated, a LookupRecord data block is used to determine whether the assigned technician is currently assigned to an open service request. If this is true, then the Before Change event is cancelled and the record is not updated.

Sample code provided by: The Microsoft Access 2010 Programmer’s Reference

/* Get the name of the technician  */
Look Up A Record In tblTechnicians
    Where Condition =[tblTechnicians].[ID]=[tblServiceRequests].[AssignedTo]
SetLocalVar
    Name TechName
    Expression [tblTechnicians].[FirstName] & " " & [tblTechnicians].[LastName]
/* End LookUpRecord  */

If Updated("AssignedTo") Then
    Look Up A Record In tblServiceRequests
        Where Condition SR.[AssignedTo]=tblServiceRequests[AssignedTo] And 
            SR.[ID]<>tblServiceRequests.[ID] And IsNull(SR.[ActualCompletionDate])
        Alias SR
        RaiseError
            Error Number 1234
            Error Description ="Cannot assign a request to the specified technician: " & [TechName]

End If

Wrox Press is driven by the Programmer to Programmer philosophy. Wrox books are written by programmers for programmers, and the Wrox brand means authoritative solutions to real-world programming problems.

Show: