PDA

Click to See Complete Forum and Search --> : What's the name of my function??


Martin5260
Jan 28th, 2000, 05:53 AM
Hi there!

I'm writing an error handler that let's the user (and eventually the programmer) know what function was processing when the error occurred. The error message includes:
- form name
- function name
- error description

So, for form, I can use me.name (form name)
For the error, I can use err.description (description of error).
But how do write the function name (without having to hardcode the function name each time)????

Here's a little code if that makes it clearer?


CODE:

Exit Sub
error:
If ProcessError(Err, Me.Name, "UpdateControls") = vbYes Then
Resume Next
End If

So, instead of writing "UpdateControls" or whatever my function name is, I'd like a way to automatically fill it in.

Thank you very, very much!!
Andrea :)

seaweed
Jan 28th, 2000, 06:37 AM
Well, this is a simple (but probably non-professional) way to solve the problem...use a property proceedure!

Create a property called "CurrentProceedure" that holds the name of the most recent proceedure executed.

The drawback is that the first line of each function must assign the function name to the property, but it WOULD enable cutting and pasting of your error handler without manually typing in the function name each time, i.e:

If ProcessError (Err, Me.Name, Me.CurrentFunction) = vbYes Then
Resume Next

MartinLiss
Jan 28th, 2000, 06:41 AM
There isn't any way. What I do is to code the declaration of my common error routine this way: Public Sub DisplayError(sRoutine As String) and in each routine that has an error handler I do ErrorRoutine:

If Err.Number <> 0 Then DisplayError "CalcDiskType" where "CalcDiskType" is the procedure name. It's really not a lot of effort to do that.


------------------
Marty
COGITO EGGO SUM
I think; therefore I am a waffle.

seaweed
Jan 28th, 2000, 06:41 AM
P.S. I sure misspelled procedure a lot! Also, if the procedure is called "CurrentProcedure", then my example should have read:

If ProcessError (Err, Me.Name, Me.CurrentProcedure) = vbYes Then
Resume Next