Visual Basic Programming Code Examples Visual Basic > Applications VBA Code Examples Errorhandler - A logged error handler Errorhandler - A logged error handler Private fs As FileSystemObject Private strLogPath As String Private strErrorLine As String Private strErrorHeader As String Private strLogFile As String Private inttest As Integer Private Sub Form_Load() Set fs = New FileSystemObject On Error GoTo ErrorHandler 'CREATE AN ERROR BELOW FOR DEMONSTRATING THE HANDLER inttest = 20002292345# 'REST OF PROGRAM CODE............. Exit Sub ErrorHandler: strLogFile = App.EXEName & ".log" strLogPath = App.Path If Not (fs.FolderExists(strLogPath)) Then MkDir (strLogPath) If Not (fs.FileExists(strLogFile)) Then Open strLogPath & "\" & strLogFile For Output As #1 Close #1 End If Open strLogPath & "\" & strLogFile For Append As #1 strErrorHeader = "***** ERROR LOG REPORT FOR : " & Err.Source & ", CREATED AT " & Now & " *****" Print #1, strErrorHeader & vbNewLine strErrorLine = "***** Error No: " & CStr(Err.Number) & " - " & _ "Description: " & Err.Description & " *****" Print #1, strErrorLine & vbNewLine strErrorLine = "***** END OF REPORT ****" Print #1, strErrorLine & vbNewLine & vbNewLine & vbNewLine Close #1 Resume Next End Sub