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:
  1. Option Explicit
  2.  
  3. Public Sub myErr(UserName As String, FormName As String, ProcedureName As String, Optional Comments As String)
  4.  
  5.   Select Case FormName & ProcedureName
  6.    
  7.     Case "Form1" & "Command1_Click()"
  8.      
  9.       If Err.Number = 6 Then
  10.         MsgBox "Overflow dumbass"
  11.         Exit Sub
  12.       End If
  13.    
  14.     Case "Form1" & "Command2_Click()"
  15.      
  16.       If Err.Number = 6 Then
  17.         MsgBox "Overflow dumbass"
  18.         Exit Sub
  19.       End If
  20.      
  21.   End Select
  22.  
  23.   Call logError(UserName, Err.Number, Err.Description, Err.Source, FormName, ProcedureName, Comments)
  24.  
  25. End Sub
  26.  
  27. 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)
  28.  
  29. Dim errFile As String, fNum As Integer
  30.  
  31.   On Error GoTo errHand
  32.  
  33.   errFile = App.Path & "\Errors.log"
  34.   fNum = FreeFile
  35.      
  36.   Open errFile For Append As fNum
  37.     Print #fNum, UserName & ", " & Now & ", " & ErrNumber & ", " & ErrDescription & ", " & ErrSource & ", " & FormName & ", " & ProcedureName & ", " & Comments
  38.   Close #fNum
  39.  
  40.   MsgBox "Error Number: " & ErrNumber & vbCrLf & vbCrLf & ErrDescription, vbCritical, FormName & " - " & ProcedureName
  41.  
  42.   Exit Sub
  43.  
  44. errHand:
  45.  
  46.   Close #fNum
  47.   MsgBox Err.Number & vbCrLf & Err.Description, , "logError Error"
  48.  
  49. End Sub