Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Visual Basic (Microsoft) Versions 5/6 FAQ

Error Trapping

How can I trap errors and write them to a log file? by Michael42
Posted: 13 Feb 03

Global Variable:
mNL$ = Chr$(13) & Chr$(10)

Sub mySub1()
   On Error Goto err_mySub1
   'Your Code for current sub or function

    Exit Sub

    Screen.MousePointer = DEFAULT
    sLogError Error, Err
    Select Case Err
        Case 3021 'No Current Record
            Resume Next
        Case Else
            mRetVal% = MsgBox("SubName999" & mNL & mNL & Error & mNL$ & mNL$ & "Error number: " & Str$(Err), MB_ICONINFORMATION, "Internal Error")
            Resume Next
    End Select

Sub sLogError (pErrMsg As String, pErrNumber As Long)
   On Error Resume Next
   'Write Error To Error Log
   Dim mLogFile As Integer
   mLogFile% = FreeFile
   Open app.Path & "\Error.log" For Append As #mLogFile%
   Print #mLogFile%, "<<<<<<<<<< " & Date$ & " - " & Time$ & " >>>>>>>>>>" & mNL
   Print #mLogFile%, pErrMsg$ & mNL$ & mNL$ & "Error number: " & Str$(pErrNumber)
   Close #mLogFile%

End Sub

Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close