BukHix
05-07-2002, 05:05 PM
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
<pre id=code><font face=courier size=2 id=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
</font id=code></pre id=code>
As I have it now it is inside the sub like this:
<pre id=code><font face=courier size=2 id=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
</font id=code></pre id=code>
He who joyfully marches in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would suffice. - Albert Einstein & BukHix Liberty1st.org ( http://www.liberty1st.org/forum/ )
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
<pre id=code><font face=courier size=2 id=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
</font id=code></pre id=code>
As I have it now it is inside the sub like this:
<pre id=code><font face=courier size=2 id=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
</font id=code></pre id=code>
He who joyfully marches in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would suffice. - Albert Einstein & BukHix Liberty1st.org ( http://www.liberty1st.org/forum/ )