Attribute VB_Name = "basErrorLog"
'---------------------------------------------------------------------------------------
' Module    : basErrorLog
' DateTime  : 11/24/2003 10:03
' Author    : Bennet Oberholzer
' Purpose   : This module allows for easy error trapping.  All procedures/functions
'             that have a call to this procedure in them will write out to an output
'             file called "error.log" with a timestamp, error description, and
'             errored procedure.  This is for debugging purposes only.  This module
'             is kept seperate from the others in the thinking that it will only be
'             called if an error occurs (which will hopefully never happen).  This way,
'             we will not have to load it into memory unless absolutely necessary.
'---------------------------------------------------------------------------------------

Sub LogError(ErrorNumber As Integer, ErrorDescription As String, ErrorSource As String, Fatal As Boolean, FunctionName As String, Optional FileName As String, Optional SuppressLogError As Boolean)

On Error GoTo ErrorHandler

Dim ErrorRec As String
Dim filenum As Integer

frmMain.lblErrors.Visible = True

ErrorRec = "Error " & ErrorNumber & " - " & ErrorDescription & vbTab & FunctionName & vbTab & "Source: " & ErrorSource & vbTab & Now() & vbTab & GetUserName

If ERROR_LOG_PATH = "" Then
    ERROR_LOG_PATH = App.Path & "\error.log"
End If

filenum = FreeFile
If FileName = "" Then
    Open ERROR_LOG_PATH For Append As #filenum
Else
    Open FileName For Append As #filenum
End If

Print #filenum, ErrorRec
Close #filenum

If Fatal = True Then
    MsgBox "A fatal error has occurred." & vbNewLine & "This program will now end." & vbNewLine, vbCritical, "Fatal Error"
    End
End If

Exit Sub

ErrorHandler:

If Not SuppressLogError And Not ERROR_DIALOG_RAISED Then
    ERROR_DIALOG_RAISED = True
    MsgBox "An Error Has Occurred in the Error Logger." & vbNewLine & "Please record this and forward it to your System Administrator." & vbNewLine & vbNewLine & _
            "Calling Function: " & FunctionName & vbNewLine & _
            "FileName: " & FileName & vbNewLine & _
            "Program: " & App.Title & vbNewLine & _
            "Version: " & App.Major & "." & App.Minor & "." & App.Revision & vbNewLine & _
            "Date/Time: " & Now() & _
            "Error " & ErrorNumber & "-" & ErrorDescription _
            , vbOKOnly, "Error"
    ERROR_DIALOG_RAISED = False
End If

Resume Next

End Sub

