Results 1 to 2 of 2

Thread: Help: How to programmatically retrieve sub/function name?

  1. #1
    Guest

    Question

    Retrieving the form name as "me.name" is similiar to what I wish to do with a Sub or Function's name.

    If I have "Private Function PTSBuildReport(rsReport As Recordset)" and an error occurs, how might I retrieve:

    Err.Number & Me.Name & "Sub/Function Name"?

    Thanks!

    Nick

  2. #2
    Guest
    I don't think there is a way to retrieve the name via code. But if you handle the errors within your subs/functions, then you copuld do this:
    Code:
    Private Sub MyFirstSub1()
       On Error Goto ErrHandler
       '...Regular sub code comes here...
       Exit Sub
    ErrHandler:
       MsgBox Err.Number & ": " & Err.Description & vbCrLf & "MyFirstSub1" & ", " & Me.Name
    End Sub
    Private Function AnotherFunction34() As String
       On Error Goto ErrHandler
       '...Regular function code comes here...
       Exit Function
    ErrHandler:
       MsgBox Err.Number & ": " & Err.Description & vbCrLf & "AnotherFunction34" & ", " & Me.Name
    End Function
    Private Sub MyOtherCoolSub()
       On Error Goto ErrHandler
       '...Regular sub code comes here...
       Exit Sub
    ErrHandler:
       MsgBox Err.Number & ": " & Err.Description & vbCrLf & "MyOtherCoolSub" & ", " & Me.Name
    End Sub
    Since you know the names of your subs/functions you can just store them at design-time.

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