Error Trapping (Mile-O)

MattS

Crabby Cancerian.....
Local time
Today, 20:43
Joined
Jun 18, 2003
Messages
130
Mile-O,

Saw your response to one of ColinEssex' posts, and your comments regarding an error trapping subroutine to write all of the details to a table.

I'm fine to create the code to do it, but was wondering how you dealt with subroutines and functions that are called from many places. i.e. do you simply trap that the error occured in the sub/function, or do you carry in some sort of variable to identify where it was originally called from.

Trust the above makes sense, and thanks for your help and advice.

Matt.
 
I know, on some occasions, error trapping is used to correct data that may go awry at runtime but I prefer to show the error message (the users just ignore it anyway) but pass information to this function which writes it to a table.

It's pretty basic stuff:

Code:
[b].....[/b]

On Error Goto Err_ErrorHandler

    [i]bla bla bla[/i]

Exit_ErrorHandler:
    Exit Sub

Err_ErrorHandler:
    Call ErrorHandler(Err.Number, Err.Description, "cmdComplete_Click", Me.Name)
    Resume Exit_ErrorHandler

End Sub


I just have a single function in a module called ErrorHandler.

This function receives the data as sent in the previous procedure (this is done in all subs where data may go stupid (some don't need it at all as there's never going to be an error in them).

It just uses DAO to write the data sent into a table adding the time of the error and the user's name via the GetUserName function.

Das ist alles.


:)
 
Nein, wir kommen aus Glasgow.


Wir? :) ;) :rolleyes: :mad: :p <-----Wir!
 
You're a dark horse, Mile-O-Phile. I was certain you were a Californian. (No offence, guv.) I am writing about you in an obscure publication. I'm going to have to make some changes.

Be handy to know what you put in that ErrorHandler module. Please.
Cheers
 
kupe said:
You're a dark horse, Mile-O-Phile. I was certain you were a Californian. (No offence, guv.)

LOL :p

I am writing about you in an obscure publication.

Mile-O-Phile and the Philosopher's Stone?
Trumpet Buyer's Monthly?
IKEA Catalogue Winter Edition, 2006?
 
kupe said:
Be handy to know what you put in that ErrorHandler module


...run of the mill stuff.


Code:
Public Sub ErrorHandler(ByVal lngError As Long, ByVal strError As String, _
    ByVal strSub As String, ByVal strForm As String)
    
    On Error GoTo Err_ErrorHandler

    Dim db As DAO.Database, rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblErrors")
    
    With rs
        .AddNew
        .Fields("AppName") = gAPPNAME
        .Fields("ErrorNumber") = lngError
        .Fields("ErrorDescription") = strError
        .Fields("SubRoutine") = strSub
        .Fields("User") = GetUserName
        .Fields("FormModuleName") = strForm
        .Update
        .Close
    End With
    
    Set rs = Nothing
    Set db = Nothing
    
    MsgBox "Error " & lngError & vbCrLf & vbCrLf & strError & vbCrLf & vbCrLf & strSub & vbCrLf & vbCrLf & strForm, vbCritical, gAPPNAME
    
Exit_ErrorHandler:
    Exit Sub
    
Err_ErrorHandler:
    MsgBox "An error has occurred in the Error Handling Routine." & vbCrLf & vbCrLf & _
        Err.Description, vbExclamation, gAPPNAME & " : Error #" & Err.Number
    Resume Exit_ErrorHandler

End Sub


See what I mean?
 
Run of the mill to you, oh Master. Dizzily hi-tech words from On High for some of us. Many thanks for it.

Of the publication: well, of a much higher order, naturally, for the Laird of access-programmers.co.uk. I'll tell you more when the wider world gets a chance to reel with the new knowledge/wonder of you.

All the best.
 
Such modesty. Go on, you know you're great (even if perhaps not the most patient craftsman on earth), and why shouldn't the wider world be told? Cheers ;)
 

Users who are viewing this thread

Back
Top Bottom