I'm thinking of creating a central error handling routine that I can call from all procedures in a project. I'm not sure what the best way to do this would be though.
Should I use a select statement on form name and procedure name??? I could see this getting out of control on most of my projects. If anyone has any comments or suggestions, I would appreciate them.
Here is what I am thinking:
VB Code:
Option Explicit Public Sub myErr(UserName As String, FormName As String, ProcedureName As String, Optional Comments As String) Select Case FormName & ProcedureName Case "Form1" & "Command1_Click()" If Err.Number = 6 Then MsgBox "Overflow dumbass" Exit Sub End If Case "Form1" & "Command2_Click()" If Err.Number = 6 Then MsgBox "Overflow dumbass" Exit Sub End If End Select Call logError(UserName, Err.Number, Err.Description, Err.Source, FormName, ProcedureName, Comments) End Sub Private Sub logError(UserName As String, ErrNumber As String, ErrDescription As String, ErrSource As String, FormName As String, ProcedureName As String, Optional Comments As String) Dim errFile As String, fNum As Integer On Error GoTo errHand errFile = App.Path & "\Errors.log" fNum = FreeFile Open errFile For Append As fNum Print #fNum, UserName & ", " & Now & ", " & ErrNumber & ", " & ErrDescription & ", " & ErrSource & ", " & FormName & ", " & ProcedureName & ", " & Comments Close #fNum MsgBox "Error Number: " & ErrNumber & vbCrLf & vbCrLf & ErrDescription, vbCritical, FormName & " - " & ProcedureName Exit Sub errHand: Close #fNum MsgBox Err.Number & vbCrLf & Err.Description, , "logError Error" End Sub








Reply With Quote