I have a logging routine that's supposed to silently log errors caught by
error handler code on certain functions. The problem is sometimes stuff
happens and the error handler can get caught in a loop. Is there some way
to send a break from VBA code to break out of the loop?
Here's what the error handler code looks like:
[MyForm module]
Private Function MyFunction
On Error GoTo HandleErr
[code here]
Exit_Here:
Exit Function
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr "MyForm", "MyFunction"
End Select
Resume Exit_Here
End Function
Here's what modHandler.LogErr looks like:
[modHandler module]
Public Sub LogErr(strErrFrm As strString, strErrFunc As String)
Dim db As DAO.Database
Dim strErrMsg As String
Dim strSql As String
strErrMsg = Err.Description
strSql = "INSERT INTO tblErrorLog ( ErrMsg, ErrFrm, ErrFunc ) " & _
"VALUES (strErrMsg, strErrFrm, strErrFunc);
Set db = CurrentDb
db.Execute strSql
Set db = Nothing
End Sub
If something weird happens, I don't want LogErr to get caught in a loop. I
was thinking of something like this:
Public Sub LogErr(strErrFrm As String, strErrFunc As String)
Dim db As DAO.Database
Dim strErrMsg As String
Dim strSql As String
If Nz(Forms("MyForm")!txtLastErr, Now() - 1) >= (Now() - 0.00001) Then
MsgBox "we're in a loop"
[***code to break the loop?***]
Else
Forms("MyForm")!txtLastErr = Now()
strErrMsg = Err.Description
strSql = "INSERT INTO tblErrorLog ( ErrMsg, ErrFrm, ErrFunc ) " & _
"VALUES (strErrMsg, strErrFrm, strErrFunc);
Set db = CurrentDb
db.Execute strSql
Set db = Nothing
End If
End Sub
Is there some way -- other than Application.Quit :) -- to break out of the
loop? Other options?
Thanks in advance.