I have been very lax in building error trapping into my DB applications and am now working on one that requires it.
Can I put this into a function and call it whenever I have an error anywhere in the form? If so what is the best way to do it? I have a basic idea of how to call functions am looking for "best practices" when it comes to error trapping for an entire form
As I have it now it is inside the sub like this:
Can I put this into a function and call it whenever I have an error anywhere in the form? If so what is the best way to do it? I have a basic idea of how to call functions am looking for "best practices" when it comes to error trapping for an entire form
Code:
If err <> 0 Then
Dim msgError As String
msgError = "Error # " & Str(err.Number) & " was generated by " _
& err.Source & vbCrLf & err.Description & vbCrLf & vbCrLf & _
"An error message has been sent to Buck"
MsgBox msgError, , "Erro", err.HelpFile, err.HelpContext
DoCmd.SendObject , , , "hicksb@ritsema.com", , , _
"Database Problem", msgError, False
Exit Sub
End If
As I have it now it is inside the sub like this:
Code:
Private Sub EmpID_Exit(Cancel As Integer)
Dim fname As String, lname As String, txtFullName As String
On Error Resume Next
lname = DLookup("[LastName]", "EmployeeList", "[EmployeeNumber]=" & Me!EmpID)
fname = DLookup("[FirstName]", "EmployeeList", "[EmployeeNumber]=" & Me!EmpID)
Me.txtEmployeeName = (fname & " " & lname)
If err <> 0 Then
Dim msgError As String
msgError = "Error # " & Str(err.Number) & " was generated by " _
& err.Source & vbCrLf & err.Description & vbCrLf & vbCrLf & _
"An error message has been sent to Buck"
MsgBox msgError, , "Erro", err.HelpFile, err.HelpContext
DoCmd.SendObject , , , "hicksb@ritsema.com", , , _
"Database Problem", msgError, False
Exit Sub
End If
End Sub