Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

General Error Handling

Status
Not open for further replies.

EriRobert

MIS
May 9, 2003
114
GB
Hello

My form based procedures are in the format:

Code:
Private Sub ProcedureName()
On Error GoTo ErrorSection

      ……
     Exit Sub
 
ErrorSection:
    MsgBox "Error occured in Form: " & Me.Form.Name & vbCrLf & _
            "Routine: ProcedureName" & vbCrLf & _
            "Error Code: " & Err.Number & vbCrLf & _
            "Description: " & Err.Description
    Resume Next
End Sub

Within the Error section is there any straightforward way to refer to the current procedure name so that I don't have to keep changing it as I copy it around [Me.Procedure.Name sort of thing].

... or is there a better way to do this. I want to know the procedure name when an error occurs.

Thanks
 
Right off hand I can not think of one. You may want to check into the err.raise function. Basically create your own error codes and be able to trace them that way.



Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
That's a good question EriRobert.
The answer to, which I have been desirous of, for a long time.

I don't think there is.

But, thanks to "Zada Solutions", I downloaded there
"Error Handler Builder", which automatically,
puts Error handling code, in every procedure of my dBase.

Their code, includes the Procedure name.

Long story, but you can customize the procedure,
Using code words they offer.

To make a long story short, check out their website.

I was able to incorporate my own ErrorLog procedure,
with theirs, which gave me the name of the procedure,
the error occured in.

Good Luck!
 
If you are feeling real ambitious and want to make a solution you can use again and again. You may want to write some code to search for the "Routine: ProcedureName" string and replace it with the procedure name. Access has some cool objects and methods of finding the string, finding the proc name and changing the strings. Then you could run the code to update the modules.
 
how about:

Code:
Call LogError(Module.Name & "at " & Module.ProcOfLine(Module.CountOfLines, vbext_pk_Get), CurrentUser, (Err.Number & " " & Err.Description))

Where LogError is a routine that writes the error data in a table or logfile
 
Which will work nice and dandy on mdb files, but how does it work on mde's?

Roy-Vidar
 
If I'm not mistaken, just looking at the code,
the only name it will give you, is the LAST procedure, in a module?
Am I wrong?
 
And so I did?

Sub CodeName()
Dim mdl As Module
Set mdl = Application.Modules(VBE.ActiveCodePane.CodeModule)
Debug.Print mdl.ProcOfLine(mdl.CountOfLines, vbext_pk_Get)
End Sub

Results as expected, last Sub/Function in Module.
Irrespective of where I place it?
 
In case anyone didn't know already (I just found out),
You can get the line in your code, where an error occured.
This "undocumented" property, is part of the Err Object.
You invoke it with "Erl".
And If I'm not Mistaken, your module must have line numbers.
Again, an Add-In offered by FMS, mzTools, I think Zada.

SO, with that little bit of knowledge,
One should quite easily find the Procedure name,
using the ProcofLine method (during an error, which I think
was the original objective).

again guys, no luck with the easyit's code,
using my modification in a Standard module, &
easyit's in a class?

 
Hm - did a very brief test of this some time ago, where I seem to recall it working in mdb's, but wouldn't make it to an mde (probably due to relying on the textual representation of the code?) - now it seems to work as you say - that much for my testing ...

The erl thingie - well, wouldn't you need manual numbering of all the lines, then? Doesn't the ProcOfLine method accept the actual line number in the module? If so, that's probably somewhat worse than passing the sub/function name "manually"

Let's see if there are some special trick that easyit has to offer ...

Roy-Vidar
 
Guys, I'm sorry.
It seems the "Add Line Numbers" feature in mzTools' add-in,
Numbers your lines, according to procedure, not by module.

You won't get an accurate reading(produre name) using,
MsgBox "Error Line: " & Erl & vbCrLf & vbCrLf & _
"ProcName;" & mdl.ProcOfLine(Erl, vbext_pk_Proc) & vbCrLf & vbCrLf & _
"Error: (" & Err.Number & ") " & Err.Description, vbCritical
 
Roy, easyit, excuse my tenacity on this issue,
but I'm really perplexed on why easyit's code is not working for me, but for both of you?
Especially since in theory, if I'm not mistaken,
it shouldn't work( for a module with more than 1 Procedure).

..again, I've been working on this on & off, for some time,
so I was thrilled to hear, there might be a way,
even though most of the websites a I searched,
concurred that there was no inherent method in Access,
to obtain the current procedure name?

Either way, Thx!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top