Trap Form errors

Djblois

Registered User.
Local time
Yesterday, 19:34
Joined
Jan 26, 2009
Messages
598
This is the code I use to trap Form Error Codes:

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)

    On Error GoTo err_handler

    Response = acDataErrContinue
    FormError "frmScheduled_Appts-Form_Error", DataErr, Screen.ActiveControl.Name
    Exit Sub
    
err_handler:
    
    CloseForm "frmGeneralError"
    
    On Error GoTo err_handler2
    
    FormError "frmScheduled_Appts-Form_Error", DataErr, Screen.ActiveControl.Name
    
    Exit Sub
    
err_handler2:
    
    FormError "frmScheduled_Appts-Form_Error", DataErr
    
End Sub

The only issue that I am having is how do you trap the Error Description in a form error? I am already trapping the number but not the description.
 
I prefer my simple routine for error trapping...

Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
 
    MsgBox "testing"
 
Exit_Form_Open:
    Exit Sub
 
Err_Form_Open:
    MsgBox Err.Number & " - " & Err.Description, vbCritical, "Form_Open()"
    Resume Exit_Form_Open
 
End Sub

If I need to trap for a specific error number then I simply add it...
Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
 
    MsgBox "testing"
 
Exit_Form_Open:
    Exit Sub
 
Err_Form_Open:
    If Err.Number = 1234 Then
        MsgBox "User error # 1234", vbCritical, "Abort"
        Resume Exit_Form_Open
    Else
        MsgBox Err.Number & " - " & Err.Description, vbCritical, "Form_Open()"
        Resume Exit_Form_Open
    End If
 
End Sub
 

Users who are viewing this thread

Back
Top Bottom