-
I'm writing a error trapping and logging routine for
a program I made a few weeks ago. It has some
quite long functions, so I made a error logging
routine. The program is called from the other functions
like as below,
sub test
on error goto error
end sub <-----------------------------------
error: |
call errorfunc |
end sub |
|
I even tried it by changing the first end sub | to end,
but my program stops executing every time somewhere.
I need the program to continue through the errors. but log them so I can go back and fix them for different customers
below is my error function if you're interested.
Public Function LogError(ByVal ErrDateTime As Date, ByVal procname As String, ByRef ErrObj As ErrObject, Optional FormObject As Object, Optional CommandString As String)
Dim intFileO As Integer
ErrDateTime = (Date)
On Error Resume Next
intFileO = IntFile(0)
MsgBox ("An error occured, and a Log file is being created")
Open App.Path & "\Error.log" For Append As intFileO
If IsMissing(FormObject) And IsMissing(CommandString) Then
Write #intFileO, ErrDateTime, procname, ErrObj.Description,
ErrObj.Source
ElseIf Not IsMissing(FormObject) And Not IsMissing(CommandString) Then
Write #intFileO, ErrDateTime, procname, ErrObj.Description,
ErrObj.Source , FormObject.Caption, CommandString
' a routine to dump all values found in a form
Call DumpFormValues(intFileO, frmRecordCard)
ElseIf Not IsMissing(CommandString) Then
Write #intFileO, ErrDateTime, procname, ErrObj.Description,
ErrObj.Source , CommandString
End If
Close intFileO
On Error GoTo 0
Err.Clear
On Error GoTo errhndlr
End Function
errhndlr: Call LogError(ErrDateTime, procname, ErrObj, FormObject, CommandString)
End Function
-
Always use the 'exit function' or 'exit sub' before the error handler.
This will fix yr prb. :)
-
End is bad
Jerry is correct, by switching to end you exit the application. Using Exit sub and function would fix the problem