Results 1 to 9 of 9
  1. #1
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Error Messages and Logging Errors (Access 2003)

    For a while now I have been adding an errors table to my databases, and including an error logging procedures to each error handler.
    I use MZ Tools so I have modified the standard error handler it generates.

    So an error handler might look like this:

    sbCreateItems_Error:
    If Err.Number = 0 Then
    Resume Next
    ElseIf Err.Number = 91 Then
    Resume Next
    Else
    sbLogerror Err.Number, Err.Description, "sbCreateItems of VBA Document Form_frmAuctionDetails"
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure sbCreateItems of VBA Document Form_frmAuctionDetails", , "Error"
    Resume Exit_sbCreateItems
    End If

    The error logging works OK. sbLogerrors is a procedures that adds a record to the errors table, that also has data/time field, and user field.

    However the error message looks like the one shown below (although that is from a different procedure.)

    <font color=red>Is it the case that calling another procedure (sbLogerror) causes the system to lose track of the values in err. number and err. description?</font color=red>
    If I display the error message before I log the error, the error message contains the number and description , so I know how to fix the problem, but I am just looking for an explanation.

    Actually I am not sure it is really a problem. Users don't actually read the error messages, so what they see is all they want anyway.
    Regards
    John



  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Error Messages and Logging Errors (Access 2003)

    Does the procedure sbLogerror contain an error handler of its own (On Error ...)? That would clear the Err object - there is only one Err object, shared by all VBA code.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Error Messages and Logging Errors (Access 2003

    Thanks Hans

    Yes it does. That explains it. So either I get rid of that, or I reverse the order, or I just simplify the message to something like:

    MsgBox "An Error has occured in procedure sbCreateItems of VBA Document Form_frmAuctionDetails", , "Error"

    This is not as good for me. While debugging I need to look in the errors table to find out what it was.
    Regards
    John



  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Error Messages and Logging Errors (Access 2003

    Displaying the message box before calling sbLiogError is probably the easiest solution. Another would be to display the message box in sbLogError, using the arguments passed to it:

    Sub sbLogError(lngErrNumber As Long, strErrDescription As String, strErrSource As String)
    ...
    MsgBox "Error " & lngErrNumber & " (" & strErrDescription & ") in procedure " & strErrSource, , "Error"
    ...
    End Sub

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Error Messages and Logging Errors (Access 2003

    Whatever I do I have to revisit hundreds of error procedures and make the change.

    If I put the mesage box into the error logging procedure I have to get rid of every one that is currently in an error handler first, overwise I will get two messages boxes.
    Regards
    John



  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Error Messages and Logging Errors (Access 2003

    Yes, it'll be a lot of work <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Error Messages and Logging Errors (Access 2003

    It is my fault.

    I have been meaning to solve this problem for ages, and instead I just kept putting in the current one that does the wrong thing.
    Regards
    John



  8. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Error Messages and Logging Errors (Access 2003

    Do you have to change it. Can't you just record the Err.Number, Err.Description etc in local variables in the logging function as the first thing you do in the logging function, then turn on the error handler in your logging function etc etc, viz.

    Public Sub LogError()
    Dim lngErrNumber as long, strErrDescription
    lngErrNumber = Err.Number
    lngErrDescription = Err.Description
    On Error Goto Err_LogError
    .
    .
    .

  9. #9
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Error Messages and Logging Errors (Access 2003

    Thanks Patt, but I don't this will work, as far as saving me having to change each error handler.

    You are right that I could capture the err.number and err.description in local variables in sbLogError, but if I then do anything with them here I have to go back to each of the event procedures and remove the message box.


    What happens if I just remove the error handler from sbLogerror?

    I had a similar situation today where an event procedure called another sub (that did not have an error handler) and an error occured, The error number and description were correctly reported by the calling procedure's error handler. (once I moved it to come before the error logging call.)

    So if I just removed the error handler from sbLog error and an error occurs in sbLog error, the user would see a message box with the error that occured in sblog error rather than the original error that started it, but otherwise it would work OK.

    ( I suspect that what I just said is as clear as mud.)
    Regards
    John



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •