What is wrong with my "on Error" logic?

I have created a system to get familiar with "on Error" logic. It is isolated and simple, yet when my main logic calls on a sub, which calls on a sub, which calls on a sub, all of which will invoke the "on error" logic created in the main logic.  The main, the first sub, and the second create errors and I expect the "on error" logic to be invoked by all three. The main calls on the first sub and that works OK, but it doesn't continue on to the next sub. It doesn't work. I have attached my simple DB - one empty table and a form with only 1 control to start the logic.

Any help?
OnErrorTestForm.pdf
TestOnErrorLogic.accdb
SowleManRetiredAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
Not sure I follow all your: "Call/On Error/GoTo" ...logic there...?

...In any event, if you need logging you might want to try something "simple" first, ...something roughly like this:

Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

'Test code to automatically throw an error
Dim agg As Byte
    agg = 999

Exit_Command11_Click:
    Exit Sub

Err_Command11_Click:
    'Display the Eror description to the user
    MsgBox Err.Description
    'Set the sub name variable
    gstrCalledFrom = "Command11_Click"
    'Cal to the Error Logging sub
    Call ErrorLog
   
    Resume Exit_Command11_Click
    
End Sub


Private Sub Command12_Click()
On Error GoTo Err_Command12_Click

'Test code to automatically throw an error
Dim agg As Byte
    agg = "Junk"

Exit_Command12_Click:
    Exit Sub

Err_Command12_Click:
    'Display the Eror description to the user
    MsgBox Err.Description
    'Set the sub name variable
    gstrCalledFrom = "Command12_Click"
    'Cal to the Error Logging sub
    Call ErrorLog
   
    Resume Exit_Command12_Click
    
End Sub

Sub ErrorLog()
' Error logging Code
    Dim db As DAO.Database
    Dim ErrLog As DAO.Recordset
    Set db = CurrentDb()
    Set ErrLog = db.OpenRecordset("tblerrorlog", dbOpenDynaset)
    With ErrLog
        .AddNew
            .Fields("errdate") = Now()
            .Fields("errnbr") = Err.Number
            .Fields("errdscr") = Err.Description
            .Fields("ErrCalledFrom") = gstrCalledFrom
        .Update
    End With
    Set db = Nothing
    Set ErrLog = Nothing
End Sub

Open in new window


This works fine for me, and my error log looks like this:
errID      errDate                                      errnbr      errdscr                      ErrCalledFrom
5              8/28/2015 4:04:56 PM              6              Overflow              Command11_Click
6              8/28/2015 4:04:58 PM              13              Type mismatch      Command12_Click


JeffCoachman
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.