Note The function, method, object, or property described in this topic is disabled if the Microsoft Jet Expression Service is running in sandbox mode, which prevents the evaluation of potentially unsafe expressions. For more information on sandbox mode, search for "sandbox mode" in Help.
Returns the error message that corresponds to a given error number (error number: A whole number in the range 0 - 65,535 that corresponds to the Number property setting of the Err object. When combined with the Description property setting of the Err object, this number represents a particular error message.).
Error [ (errornumber) ]
The optional errornumber argument (argument: A value that provides information to an action, an event, a method, a property, a function, or a procedure.) can be any valid error number. If errornumber is a valid error number, but is not defined, Error returns the string "Application-defined or object-defined error." If errornumber is not valid, an error occurs. If errornumber is omitted, the message corresponding to the most recent run-time error (run-time error: An error that can be detected only when an application is running.) is returned. If no run-time error has occurred, or errornumber is 0, Error returns a zero-length string ("").
Examine the property (property: A named attribute of a control, a field, or an object that you set to define one of the object's characteristics (such as size, color, or screen location) or an aspect of its behavior (such as whether the object is hidden).) settings of the Err object to identify the most recent run-time error. The return value of the Error function corresponds to the Description property of the Err object.
Note Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.
This example uses the Error function to print error messages that correspond to the specified error numbers.
' Loop through values 61 - 64.
For ErrorNumber = 61 To 64
' Print error to Immediate window.