G
Guest
For errors occurring in the context of controls, I can use the Err object to
capture the error number (Err.Number) and description (Err.Description).
However, I am not sure how to do this within the context of Form_Error. I
seem to be able to capture the error number, but not its description.
Here is my Form_Error Sub (goes on the Error event of all forms):
Private Sub Form_Error(DataErr As Integer, Response As Integer)
On Error GoTo ErrorHandler
DataErrCode = DataErr
ErrorHandlerForm
Response = ResponseCode
End Sub
Here, now, is a snippet of the Public Sub in a code module that handles this:
Public Sub ErrorHandlerForm()
Select Case DataErrCode
Case Is = 2113 'data type mismatch
If MsgBox("The error code is " & DataErrCode & ". Do you want to
see the system error message?", vbYesNo, "Error Code") = vbNo Then
ResponseCode = 0
Else
ResponseCode = 1
End If
Case Is = 2116 'validation rule error; handled by code
ResponseCode = 0
End Select
End Sub
It seems that the form error description does not appear until I send back a
response to the Form_Error event, and then I do not know how to capture the
description string. All I can do is, by using my ResponseCode public
variable, either show or hide the system error message. Howeer, I am now
implementing this in a non-interactive (automated) application that needs to
log the error message and send me an e-mail notification instead of
displaying the message on-screen.
capture the error number (Err.Number) and description (Err.Description).
However, I am not sure how to do this within the context of Form_Error. I
seem to be able to capture the error number, but not its description.
Here is my Form_Error Sub (goes on the Error event of all forms):
Private Sub Form_Error(DataErr As Integer, Response As Integer)
On Error GoTo ErrorHandler
DataErrCode = DataErr
ErrorHandlerForm
Response = ResponseCode
End Sub
Here, now, is a snippet of the Public Sub in a code module that handles this:
Public Sub ErrorHandlerForm()
Select Case DataErrCode
Case Is = 2113 'data type mismatch
If MsgBox("The error code is " & DataErrCode & ". Do you want to
see the system error message?", vbYesNo, "Error Code") = vbNo Then
ResponseCode = 0
Else
ResponseCode = 1
End If
Case Is = 2116 'validation rule error; handled by code
ResponseCode = 0
End Select
End Sub
It seems that the form error description does not appear until I send back a
response to the Form_Error event, and then I do not know how to capture the
description string. All I can do is, by using my ResponseCode public
variable, either show or hide the system error message. Howeer, I am now
implementing this in a non-interactive (automated) application that needs to
log the error message and send me an e-mail notification instead of
displaying the message on-screen.