RaiseError Macro Action
Last modified: July 28, 2015
Applies to: Access 2013 | Office 2013
The RaiseError action throws an exception that can be handled by the OnError macro action.
The RaiseError action is available only in Data Macros.
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:
Click the File menu, and then click Options.
In the Access Options dialog box, click the Current Database tab.
In the Navigation section, click Navigation Options.
In the Navigation Options dialog box, click Show System Objects, and then click OK.
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