Public Sub Error_Handle(ByVal sRoutineName As String, _ ByVal sErrorNo As String, _
ByVal sErrorDescription As String)
Dim sMessage As String
sMessage = sErrorNo & " - " & sErrorDescription
'Call MsgBox(sMessage, vbCritical, sRoutineName & " - Error")
With UserForm18
.Label4.Caption = sRoutineName & " [" & sMessage & "]"
.Show
End With
Call LogFile_WriteError(sRoutineName, sMessage)
End Sub
Public Function LogFile_WriteError(ByVal sRoutineName As String, _
ByVal sMessage As String)
Dim g_objFSO As Object
Dim g_scrText As Object
Set g_objFSO = CreateObject("Scripting.FileSystemObject")
Dim sText As String
Dim errdrive As String
Dim erraddress As String
errdrive = Sheets("Developer").Range("E44")
erraddress = Sheets("Developer").Range("J44")
Dim name As String
name = Sheets("Notes").Range("N4")
errfile = errdrive & "\" & erraddress & ".txt"
'On Error GoTo ErrorHandler
If (g_scrText Is Nothing) Then
If (g_objFSO.FileExists(errfile) = False) Then
Set g_scrText = g_objFSO.OpenTextFile(errfile, 2, True)
Else
Set g_scrText = g_objFSO.OpenTextFile(errfile, 8)
End If
End If
sText = sText & "" & vbCrLf
sText = sText & Format(Date, "dd MMM yyyy") & "-" & Time() & vbCrLf
sText = sText & " " & sRoutineName & vbCrLf
sText = sText & " " & sMessage & vbCrLf
g_scrText.WriteLine sText
g_scrText.Close
Set g_scrText = Nothing
Exit Function
'ErrorHandler:
Set g_scrText = Nothing
Call MsgBox("Unable to write to log file", vbCritical, name)
End Function