By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,332 Members | 1,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,332 IT Pros & Developers. It's quick & easy.

Get the name of the function or sub from within code?

P: n/a
Maybe this is just a bit too strange...
Is there a way to get the name of the Function or Sub from within that
Function or Sub?
For example, I have the following code:

Function myFunctionName(myStr as string)

'run some code here...

myExit:
Exit Function
myErr:
MsgBox Err.Number & " " & Err.Description
Resume myExit
End Function

What I want to do is this:

Function myFunctionName(myStr as string)

'run some code here...

myExit:
Exit Function
myErr:
Dim myFN as string
myFN = (code to determine myFunctionName)
Call AppendErrors(Err.Number, Err.Description, myFN, Now())
Resume myExit
End Function
sub AppendErrors(myErrNumber as long, myErrDescription as string,
_
myFunctionName as string, myDateTime as date)

'run code to insert the error into a table...

end sub

Any help is appreciated,
lq
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
No. VBA does not expose this to you, so you have to include a literal string
value for each routine.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Lauren Quantrell" <la*************@hotmail.com> wrote in message
news:47*************************@posting.google.co m...
Maybe this is just a bit too strange...
Is there a way to get the name of the Function or Sub from within that
Function or Sub?
For example, I have the following code:

Function myFunctionName(myStr as string)

'run some code here...

myExit:
Exit Function
myErr:
MsgBox Err.Number & " " & Err.Description
Resume myExit
End Function

What I want to do is this:

Function myFunctionName(myStr as string)

'run some code here...

myExit:
Exit Function
myErr:
Dim myFN as string
myFN = (code to determine myFunctionName)
Call AppendErrors(Err.Number, Err.Description, myFN, Now())
Resume myExit
End Function
sub AppendErrors(myErrNumber as long, myErrDescription as string,
_
myFunctionName as string, myDateTime as date)

'run code to insert the error into a table...

end sub

Any help is appreciated,
lq

Nov 12 '05 #2

P: n/a
Get hold of mz-tools ( http://www.mztools.com ) with this you can edit the
error handler code it inserts for you. One of the tags it automatically
converts is for the procedure name.

Terry

"Lauren Quantrell" <la*************@hotmail.com> wrote in message
news:47*************************@posting.google.co m...
Maybe this is just a bit too strange...
Is there a way to get the name of the Function or Sub from within that
Function or Sub?
For example, I have the following code:

Function myFunctionName(myStr as string)

'run some code here...

myExit:
Exit Function
myErr:
MsgBox Err.Number & " " & Err.Description
Resume myExit
End Function

What I want to do is this:

Function myFunctionName(myStr as string)

'run some code here...

myExit:
Exit Function
myErr:
Dim myFN as string
myFN = (code to determine myFunctionName)
Call AppendErrors(Err.Number, Err.Description, myFN, Now())
Resume myExit
End Function
sub AppendErrors(myErrNumber as long, myErrDescription as string,
_
myFunctionName as string, myDateTime as date)

'run code to insert the error into a table...

end sub

Any help is appreciated,
lq

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.