ACC: "Application-Defined or Object-Defined Error" Error Message
ID: Q139041
|
The information in this article applies to:
-
Microsoft Access versions 7.0, 97
SYMPTOMS
Moderate: Requires basic macro, coding, and interoperability skills.
If you use the Error() or Error$() functions to get the textual description
of an error message, you may receive the following error message:
Application-defined or object-defined error
You may receive this error message when you try to get the description of
an error trapped in a form's Error event as follows:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
MsgBox Error(DataErr)
Response = acDataErrContinue
End Sub
CAUSE
The error message being trapped is Microsoft Access specific. When you pass
an error number to the Error() function that is not a Visual Basic for
Applications specific error, Visual Basic for Applications does not call
back into the hosting application to ask it for the error message.
RESOLUTION
Microsoft Access 7.0 introduced the new AccessError method that you can use
to return the descriptive string associated with a Microsoft Access error
as follows:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
MsgBox Application.AccessError(DataErr)
Response = acDataErrContinue
End Sub
NOTE: The AccessError method will return a string associated only with
Microsoft Access errors and Visual Basic errors. It will NOT return
descriptive strings associated with data access errors.
MORE INFORMATION
Steps to Reproduce Behavior
- Open the sample database Northwind.mdb.
- Open the Orders table in Design view.
- Set the Required property of the EmployeeID field to Yes, and then
close the table.
- Click Yes to the following prompt:
Data integrity rules have been changed. Existing data may not be
valid for the new rules.
This process may take a long time. Do you want the existing data to
be tested with the new rules?
- Open the Orders form in Design view and set the following form
property:
OnError: [Event Procedure]
- Type the following code in the form module:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
MsgBox Error$(DataErr)
MsgBox Application.AccessError(DataErr)
Response = acDataErrDisplay
End Sub
- View the form in Form view and click the New Record toolbar button to
advance to a new Order record.
- Type the following line in the Bill To: combo box and press ENTER:
Hello World!
Note that you receive the following three messages:
Application-defined or object-defined error.
The text you entered isn't an item in the list.
The text you entered isn't an item in the list.
NOTE: Because the Response variable is set to acDataErrDisplay, the
error is not trapped. The third message above is the actual error
message.
- Click a customer in the Bill To: combo box list.
- Click Save Record on the Records menu. Note that you receive the
following three messages:
Application-defined or object-defined error
< a message box with no text appears >
Field 'Orders.EmployeeID' can't contain a null value.
NOTE: The second message box is empty because the error generated is a
data access error. The AccessError method does not return data access
error messages.
REFERENCES
For more information about the AccessError method, search for
"AccessError," and then "AccessError method" using the Microsoft
Access 97 Help Index.
Keywords : kberrmsg FmsOthr
Version : 7.0 97
Platform : WINDOWS
Issue type : kbprb