Results 1 to 4 of 4

Thread: What's the name of my function??

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Posts
    6

    Post

    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

  2. #2
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Post

    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



  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    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
    Code:
    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.

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Post

    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


Posting Permissions

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



Click Here to Expand Forum to Full Width