Mike & Doris Manning
mikedorism at adelphia.net
Tue Jan 13 12:43:03 CST 2004
Susan,
Here is the function I use. The calling procedure passes in the error,
procedure name, and calling form/rept. Several standard SQL Server errors
are handled. At the end, a form is popped up to let the user know what
happened and allow them to add comments, and then an email gets sent to a
specified user for corrective action.
Doris Manning
Database Administrator
Hargrove Inc.
www.hargroveinc.com
-------------------------------
Public Function HandleErrors(lngError As Long, ObjName As String, _
ObjFrom As String)
On Error Resume Next
bolHandle = False
OSUserName = fcnOSUserName()
Err.Raise lngError
Select Case Err
Case Is = -2147467259
strMsgTxt = "Connection to SQL Server has been lost. "
strMsgTxt = strMsgTxt & "Try restarting Production Manager. "
strMsgTxt = strMsgTxt & "If the problem continues then "
strMsgTxt = strMsgTxt & "reboot your computer."
MsgBox strMsgTxt, vbOKOnly, "Lost Connection"
DoCmd.Quit
Case Is = 2202, 2205, 2214 'Printer problems
strMsgTxt = "There is a problem with your printer connection. "
strMsgTxt = strMsgTxt & "Please reboot your computer. "
strMsgTxt = strMsgTxt & "If the problem persists, email the "
strMsgTxt = strMsgTxt & "Help Desk for assistance."
MsgBox strMsgTxt, vbOKOnly, "Printer Connection Problem"
bolHandle = True
Case Is = 2212 'Printer not available
strMsgTxt = "The printer you have chosen is currently "
strMsgTxt = strMsgTxt & "offline. Please select another "
strMsgTxt = strMsgTxt & "printer for your report."
MsgBox strMsgTxt, vbOKOnly, "Printer Offline"
bolHandle = True
Case Is = 2950 'Network connection lost
strMsgTxt = "There is a problem with your connection to "
strMsgTxt = strMsgTxt & "the network. Please reboot your "
strMsgTxt = strMsgTxt & "computer."
MsgBox strMsgTxt, vbOKOnly, "Lost Network Connection"
bolHandle = True
End Select
strSendSubj = "<PWOS " & BuildNo & " Error - " & ObjName
strLeadin = "Job: " & OSWONum & vbCrLf
strLeadin = strLeadin & "Source: " & ObjName & " - " & ObjFrom
strLeadin = strLeadin & vbCrLf & vbCrLf
If Err.Description = conAppError Then
strLeadin = strLeadin & "ACCESS ERROR " & Err
strLeadin = strLeadin & ": " & AccessError(lngError)
' Enumerate Errors collection and display properties of
' each Error object.
For Each errLoop In CurrentProject.Connection.Errors
With errLoop
strError = " . Error #" & .Number & vbCrLf
strError = strError & Space(10) & .Description & vbCrLf
strError = strError & Space(10) & "(Source: " & .Source &
")" & vbCrLf
End With
Next
If Len(strError) > 0 Then
strLeadin = strLeadin & vbCrLf & vbCrLf
strLeadin = strLeadin & "ADO/DAO Buffer contains "
strLeadin = strLeadin & CurrentProject.Connection.Errors.Count
If CurrentProject.Connection.Errors.Count < 2 Then
strLeadin = strLeadin & " error" & vbCrLf
Else
strLeadin = strLeadin & " errors" & vbCrLf
End If
End If
ElseIf Err.Description = vbNullString Then
strLeadin = strLeadin & "Unknown Error " & Err & " with no "
strLeadin = strLeadin & " description on file."
Else
strLeadin = strLeadin & "Unhandled Error " & Err & ": " &
Err.Description
End If
strMsgTxt = strLeadin & strError
If bolHandle = True Then
Call SendSafeEmail(strSendTo, strSendSubj, strMsgTxt, False)
Else
DoCmd.OpenForm "frmErrorInfo"
End If
End Function
Public Function SendErrorMessage()
Dim strErrorInfo As String
If IsNull(Forms!frmErrorInfo!msgDoing) Then
strErrorInfo = ""
Else
strErrorInfo = Forms!frmErrorInfo!msgDoing
End If
If Forms!frmErrorInfo!chkShowError = True Then MsgBox strMsgTxt,
vbOKOnly, "Display Error"
strMsgTxt = strMsgTxt & vbCrLf & vbCrLf & "User description of problem:"
& vbCrLf & strErrorInfo
Call SendSafeEmail(strSendTo, strSendSubj, strMsgTxt, False)
DoCmd.Close acForm, "frmErrorInfo"
DoCmd.Echo True
End Function
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Susan Harkins
Sent: Monday, January 12, 2004 10:08 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] error questions
Doris -- I'd like to see that sometime. I do agree with you both that it
wouldn't always be appropriate, but geez Louise ... give me a break!
Please!!!!!!!!!! ;)
Somewhere I've got a whole book on error handling, I really ought to read
it.
Susan H.
> John is right that you wouldn't always want to do this because
> sometimes
it
> is better to handle the issue within the calling procedure or
> function. However, I do handle some of the more common errors (such as
> lost SQL connection or printer problems) within my generic error
> handling function because that made more sense to me.
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com