J
JK
Is it recommended to include error handling on all Private Subs? When and/or
how often should I include error handling?
For example, is the following necessary?
Thanks,
Jason
Private Sub cmdAddNew_Click()
On Error GoTo Error_Handler
If vbYes = MsgBox("Add new record - are you sure?", vbYesNo + vbQuestion _
+ vbDefaultButton2, "<New Record>") Then
' Put focus on "key" control
' Make sure to save first
If Not SaveIt() Then Exit Sub
' Put myself in data entry mode
Me.DataEntry = True
Me.MailingName.SetFocus
End If
Exit_Procedure:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "An error has occurred in this application." & Err & ", " & Error
& vbCrLf & vbCrLf & _
"Please contact your technical support person and report the problem.",
vbExclamation, "Error!"
ErrorLog Me.Name & "_cmdAddNew_Click", Err, Error
' Put the focus back in the database window
DoCmd.SelectObject acTable, "ErrorLog", True
Resume Exit_Procedure
End Sub
how often should I include error handling?
For example, is the following necessary?
Thanks,
Jason
Private Sub cmdAddNew_Click()
On Error GoTo Error_Handler
If vbYes = MsgBox("Add new record - are you sure?", vbYesNo + vbQuestion _
+ vbDefaultButton2, "<New Record>") Then
' Put focus on "key" control
' Make sure to save first
If Not SaveIt() Then Exit Sub
' Put myself in data entry mode
Me.DataEntry = True
Me.MailingName.SetFocus
End If
Exit_Procedure:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "An error has occurred in this application." & Err & ", " & Error
& vbCrLf & vbCrLf & _
"Please contact your technical support person and report the problem.",
vbExclamation, "Error!"
ErrorLog Me.Name & "_cmdAddNew_Click", Err, Error
' Put the focus back in the database window
DoCmd.SelectObject acTable, "ErrorLog", True
Resume Exit_Procedure
End Sub