trap error number?

  • Thread starter Thread starter jian
  • Start date Start date
J

jian

Hi,
Can anyone tell me how to trap the error number so that I
can customize my own message?
Thanks,
jian
 
Hi Allen,
Thanks for your help. Your site is very helpful.
I was wondering why some errors still can not be trapped?
such as the data entered in a text box on a form is not
appropriate for the input mask... Is there a way to get
the err.number?
Thanks,
jian
 
Yes, use the Error event of the form to call another generic function to
handle those errors.

Example:

Public Function FormError(frm As Form, DataErr As Integer, Response As
Integer) As Integer
On Error GoTo Err_FormError
'Purpose: Generic Form_Error handler.
'Return: Response.
'Usage: In a form's Error event procedure:
' Call FormError(Me, DataErr, Response)
Dim strMsg As String
Const conDupeIndex As Integer = 3022
Const conFileMissing As Integer = 3024
Const conRelatedRecordRequired As Integer = 3201
Const conRequiredField As Integer = 3314
Const conInvalidType As Integer = 2113

Select Case DataErr
Case conDupeIndex
Response = acDataErrContinue
strMsg = "The record cannot be saved, as it would create a
duplicate."

Case conRelatedRecordRequired
Response = acDataErrDisplay

Case conRequiredField
strMsg = "This is a required field." & vbCrLf & vbCrLf & "Make an
entry, or press <Esc> to undo."
Response = acDataErrContinue

Case conInvalidType
strMsg = "Wrong type of data."
Response = acDataErrContinue

Case conFileMissing
strMsg = "Data file is currently unavailable."
Response = acDataErrDisplay

Case Else
Response = acDataErrDisplay
End Select

If Len(strMsg) > 0 Then
MsgBox strMsg, vbExclamation, "Invalid data"
End If
FormError = Response

Exit_FormError:
Exit Function

Err_FormError:
Call LogError(Err.Number, Err.Description, "FormError()", "DataErr: " &
DataErr)
Resume Exit_FormError
End Function
 
Back
Top