Sunday, June 17, 2012

Cara Membuat Generic Handler Error

Option Explicit

Private Sub Form_Load()
On Error GoTo FormLoadErr
Err.Raise 76
Err.Raise 70
Exit Sub

FormLoadErr:
Select Case Err.Number
Case 76
MsgBox "Form_Load Error Handler. Form Does Not Exist"
Case Else
AppWideErr (Err.Number)
End Select
End Sub

Private Sub Command1_Click()
On Error GoTo Cmd1Err
Err.Raise 53
Err.Raise 70
Exit Sub

Cmd1Err:
Select Case Err.Number
Case 53
MsgBox "Command 1 Error Handler"
Case Else
AppWideErr (Err.Number)
End Select
Resume Next
End Sub

Private Sub Command2_Click()
Form2.Show
End Sub

Private Sub Command1_Click()
On Error GoTo ThisSubErr
Err.Raise 17
Exit Sub
ThisSubErr:
AppWideErr (Err.Number)
End Sub

Public Sub AppWideErr(lnErrNumber)
Select Case lnErrNumber
Case 70
MsgBox "Generic Routine. Access Denied. See Net Administrator.", , "AppWideErr"
Exit Sub
Case Else
MsgBox "Generic Routine. Unhandled Error: " + Err.Description + " # " & lnErrNumber, , "AppWideErr"
Exit Sub
End Select
End Sub