473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
2 1374
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Christopher J. Bottaro | last post by:
I want to get the name of the function from within the function. Something like: def myFunc(): print __myname__ >>> myFunc() 'myFunc' Really what I want to do is to easily strip off the...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
3
by: Dennis Chang | last post by:
Hi all, I was reading about function pointers and came across something which intrigued me. K&R2 calls qsort (pg.119) within main as so: qsort( (void **) lineptr, 0, nlines-1, (int (*) (void...
8
by: CES | last post by:
All, I'm sorry but I still don't get this!! I'm trying to use a variable that is passed into a function to to dynamically name an instance of an Object(). I've created a Timer() Object that seems...
9
by: Erwin Moller | last post by:
Hi all, Is it possible (PHP5.2) to find the name of a variable used in the caller of a function from within the function itself? Or to be more clear: ...php code.. $result = foo($abc);...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.