Dynamic reference to current procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NJonge01
    New Member
    • Jun 2007
    • 44

    Dynamic reference to current procedure

    Is there a way to dynamically refer to the name of the current procedure?
    I'd like to add a dynamic reference to the current procedure in my logging procedure.

    I've googled around and found nothing (just another guy asking the same question on the utteraccess board, but with no answer).

    TIA for any help!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Interesting question.

    I had a dig around but couldn't find anything that looked remotely relevant I'm afraid.

    PS. Please let us know if you find anything.

    Comment

    • Scott Price
      Recognized Expert Top Contributor
      • Jul 2007
      • 1384

      #3
      Well... There is no direct way to do this. However, there is an indirect way that might work. Assuming you are using this for error handling/logging:
      Code:
      1:
      
      Dim cllProc As String
      
      cllProc = Me.Module.Procofline(Erl, vbext_pk_Proc)
      You might need to add a reference to the VBA Extensibility library. This would be Microsoft Visual Basic for Applications Extensibility 5.3 (or newer version number).

      This will return a string with the name of the current procedure that throws an error. The Procofline property pertains to the VBIDE.Module or Access.Module object, takes two arguments: a valid line number in the procedure, and the type of procedure... The Erl() function is the undocumented Error Line function which has a few bugs, hence the 1: label placed above the variable declaration. The Erl() function isn't too specific at times, when an error does occur, it chooses the first available line label ABOVE where the error occurred, means that if there are no line labels, it returns 0, which can affect our ProcOfLine property.

      Have I made this clear as mud, or is it somewhat understandable? :-)

      Regards,
      Scott

      p.s. Unfortunately VBA doesn't provide what VB.NET does: System.Reflecti on.MethodBase.G etCurrentMethod .Name()

      Comment

      • NJonge01
        New Member
        • Jun 2007
        • 44

        #4
        I'll give it a shot! I'm trying to log activity to a file and it sure would help.

        Thanks!

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          Scott's answer may be the most help. The best I could find was a reference to the name of the current module :
          Code:
          Me.Module.Name
          ...This only gives the same name as the object though (== Me.Name).

          Comment

          • Scott Price
            Recognized Expert Top Contributor
            • Jul 2007
            • 1384

            #6
            As an alternative to using the Erl function you could simply create a variable tuned to hold a line number within the current procedure, then refer to this variable in the Procofline() property, this is a little more suspect, though, as any changes in the code (i.e. adding a procedure above) could potentially invalidate this variable.

            Regards,
            Scott

            Comment

            Working...