function name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way in code that I can determine the name of the function that I
am in?

ie. What could I type in place of ?????? that would assign strMSG the value
of "TestMe". I would like to put that line in all of my routines and pass
strMsg to my error trapping routine.

Thanx!

'---------------------------------------------------------------
Function TestMe()
dim strMsg as string

strmsg = ??????? ' I need real code in place of question marks
msgbox strmsg,,"The name of the function is:"

end function
'---------------------------------------------------------------
 
Unfortunately there is no way to get this through code. However, you always
know what function you are in, because you are the one who wrote it!

Many people use a convention of defining a constant at the top of a
procedure:

'---------------------------------------------------------------
Function TestMe()
const CurrentProc = "TestMe"
dim strMsg as string

strmsg = CurrentProc ' I need real code in place of question marks
msgbox strmsg,,"The name of the function is:"

end function
'---------------------------------------------------------------

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Always OpenTo Suggestions" <Always OpenTo
(e-mail address removed)> wrote in message
news:[email protected]...
 
"Always OpenTo Suggestions" <Always OpenTo
Is there a way in code that I can determine the name of the function that I
am in?

ie. What could I type in place of ?????? that would assign strMSG the value
of "TestMe". I would like to put that line in all of my routines and pass
strMsg to my error trapping routine.

Thanx!

'---------------------------------------------------------------
Function TestMe()
dim strMsg as string

strmsg = ??????? ' I need real code in place of question marks
msgbox strmsg,,"The name of the function is:"

end function
'---------------------------------------------------------------


Alas, No there is no way to retrieve the name. The best
we've ever been able to do is to set a variable to the name
of of the function:

Function MyFunc( . . .
Dim strFunctionName As String
. . .
strFunctionName = "MyFunc"

Then your error handling code can pass the string as an
argument to the generic error handler or use it in error
messages.

There are some commercial tools out there on the web that
will add that code to all your procedure automatically if
you want to search for them. If you want to write your own,
take a look at
http://www.mvps.org/access/modules/mdl0031.htm
It doesn't do what you want, but it does have similar code
to what you need.
 
Back
Top