473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting Procedure Name

Can I get the name of a procedure from within the procedure? In my error
handler, I write the error to an error table. I'd like to write the name of
the procedure that's writing the error. But, rather than customizing each
error handler with the procedure name, it would be nice to be able to call a
system variable or function that gives me the procedure name and module
name. Is that possible?
Nov 15 '07 #1
13 9148
Unfortunately, VBA does not expose the name of the executing procedure, nor
the name of that module.

In case you are not aware, there is a great little utility you can download
from:
www.mztools.com
Choose the one for VBA.
Install.
It adds a toolbar to the VBA window.
You can now drop your error handler into the current procedure just by
clicking the toolbar button. And it's configurable.

For the module name, what I personally do is to declare a private constant
in the General Declarations section of every module, and assign it the name
of that module, e.g.:
Private Const conModName = "Form_frmInvoice"
Use the constant name in your error handler where you want it to pass the
module name. This arrangement requires no change to the code at all when you
copy'n'paste procedures between modules.

(You can use Module.Name, but that fails in an MDE.)

--
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.

"Neil" <no****@nospam.netwrote in message
news:gt*****************@newssvr21.news.prodigy.ne t...
Can I get the name of a procedure from within the procedure? In my error
handler, I write the error to an error table. I'd like to write the name
of the procedure that's writing the error. But, rather than customizing
each error handler with the procedure name, it would be nice to be able to
call a system variable or function that gives me the procedure name and
module name. Is that possible?
Nov 15 '07 #2
You do realize that you just posted copyrighted material.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===
bobh wrote:
On Nov 15, 10:20 am, "Neil" <nos...@nospam.netwrote:
>Can I get the name of a procedure from within the procedure? In my error
handler, I write the error to an error table. I'd like to write the name of
the procedure that's writing the error. But, rather than customizing each
error handler with the procedure name, it would be nice to be able to call a
system variable or function that gives me the procedure name and module
name. Is that possible?

Hi, there is this module I use - originaly from Access97 Developers
handbook. I have modified it a bit but it still works and I use it in
all my XP apps today.
bobh.

Option Compare Database
Option Explicit

' From Access 97 Developer's Handbook by Litwin, Getz, and Gilbert.
(Sybex)
' Copyright 1997. All Rights Reserved.

Function adhClipboardSetText(strText As String) As Variant
' Puts some text on the Windows clipboard
' From Access 97 Developer's Handbook by Litwin, Getz, and Gilbert.
(Sybex)
' Copyright 1997. All Rights Reserved.

Public Sub adhTestClipboard()
' Tests putting some text on the clipboard then reading it off again
' From Access 97 Developer's Handbook by Litwin, Getz, and Gilbert.
(Sybex)
' Copyright 1997. All Rights Reserved.

Public Sub adhReportClipboardError(ByVal intError As Integer)
' Reports an error received from the clipboard
' From Access 97 Developer's Handbook by Litwin, Getz, and Gilbert.

Public Function adhClipboardGetText() As Variant
' Gets some text on the Windows clipboard
' From Access 97 Developer's Handbook by Litwin, Getz, and Gilbert.
(Sybex)
' Copyright 1997. All Rights Reserved.
' Out:
Nov 15 '07 #3
Thanks, Allen. I remember looking at Mztools some time ago and deciding not
to get it. I'll have to have a second look. Thanks!

Neil

"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:47***********************@per-qv1-newsreader-01.iinet.net.au...
Unfortunately, VBA does not expose the name of the executing procedure,
nor the name of that module.

In case you are not aware, there is a great little utility you can
download from:
www.mztools.com
Choose the one for VBA.
Install.
It adds a toolbar to the VBA window.
You can now drop your error handler into the current procedure just by
clicking the toolbar button. And it's configurable.

For the module name, what I personally do is to declare a private constant
in the General Declarations section of every module, and assign it the
name of that module, e.g.:
Private Const conModName = "Form_frmInvoice"
Use the constant name in your error handler where you want it to pass the
module name. This arrangement requires no change to the code at all when
you copy'n'paste procedures between modules.

(You can use Module.Name, but that fails in an MDE.)

--
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.

"Neil" <no****@nospam.netwrote in message
news:gt*****************@newssvr21.news.prodigy.ne t...
>Can I get the name of a procedure from within the procedure? In my error
handler, I write the error to an error table. I'd like to write the name
of the procedure that's writing the error. But, rather than customizing
each error handler with the procedure name, it would be nice to be able
to call a system variable or function that gives me the procedure name
and module name. Is that possible?

Nov 16 '07 #4
John Spencer wrote:
You do realize that you just posted copyrighted material.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===
See:

U.S. Copyright Office - Fair Use:

http://www.copyright.gov/fls/fl102.html

I would argue that the effect of the use here would be to increase the
potential market for the book rather than decrease it. Then again,
after seeing the amount of code posted, purportedly to get the name of
the procedure, it might have a negative affect :-).

James A. Fortune
MP*******@FortuneJames.com
Nov 16 '07 #5
On Fri, 16 Nov 2007 16:31:55 -0500, "James A. Fortune"
<MP*******@FortuneJames.comwrote:
>John Spencer wrote:
>You do realize that you just posted copyrighted material.

'================================================ ====
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================ ====

See:

U.S. Copyright Office - Fair Use:

http://www.copyright.gov/fls/fl102.html

I would argue that the effect of the use here would be to increase the
potential market for the book rather than decrease it. Then again,
after seeing the amount of code posted, purportedly to get the name of
the procedure, it might have a negative affect :-).

James A. Fortune
MP*******@FortuneJames.com
I suspect that if any of those guys (Litwin, Getz, or Gilbert) were
approached, they would readily grant permission to post that function.
I can't agree, however, that this falls under "Fair Use" guidelines. I
think it is rather blatant copyright violation.

My 2 cents worth,
Arch
Nov 16 '07 #6
On Nov 15, 10:20 am, "Neil" <nos...@nospam.netwrote:
Can I get the name of a procedure from within the procedure? In my error
handler, I write the error to an error table. I'd like to write the name of
the procedure that's writing the error. But, rather than customizing each
error handler with the procedure name, it would be nice to be able to call a
system variable or function that gives me the procedure name and module
name. Is that possible?
It would be a couple of hours work I suppose to write code that would
put into each procedure as line two and three:
Dim VBProcedureName$
VBProcedureName = "Module13:Temp"
for Procedure "Temp" in Module 13.
or whatever. I suppose one would want the Module13 bit to
differentiate among various Temp private subs in various Modules.

But to what purpose?
I write my own error handling code only when I feel I need to be sure
that nothing non-VBAish is left dangling. A low level file handle is
one of these. Somewhere in the mists of time when Access was only a
gleam in the Wicked Witch of the West's eye I learned that these
should be closed. So when I open one, I do it within error handling
that will close it on error.
But almost none of my modules require that kind of fail-safe garbage
deletion. And almost none has its own error-handling.
Yes, I know, thousands of developers who write code superior to mine
are going to protest here. Such is life.

Having run the code once, then what? If we run it again we'll get
Dim VBProcedureName$
VBProcedureName = "Module13:Temp"
Dim VBProcedureName$
VBProcedureName = "Module13:Temp"

which will raise a compile error. So now we have to be sure the lines
are not already there. And if we change the name of a procedure ... I
suspect that ifs just keep rolling on here.
Nov 17 '07 #7
I don't know -- I just put an error handler in every proc, and it's worked
out well for me. For things like closing files or other things that I always
want to do, I put those under the exit label, and have the error handler
transfer to there.

In any case, you gave me an idea with the below: I could use a proc name
variable in the error handler, and set the variable at the top of the proc.
That would allow me to use a standard template for error handlers (with a
default proc name of ""), and then fill in the names as needed (in the more
problematic routines). Probably, if I had the VBProcName = "" in the
template, I'd just automatically fill it in when I start a new proc, anyway.

But, you know, it would be simple to do something like this with a Word
macro -- just plop the whole module into Word, record/write a macro that
does what's needed, and then plop the module text back into Access. Only
problem is: losing the link to event procedures. If I could be sure that the
links to control's event procedures would remain in place after I paste in
the new procs from Word, then this would be fine. But I've had bad
experiences with that in the past. Any notes/tips/etc. on trying to get the
procs to remain linked or to relink them after an event such as this?

Thanks!

Neil

"lyle" <ly************@gmail.comwrote in message
news:21**********************************@i37g2000 hsd.googlegroups.com...
On Nov 15, 10:20 am, "Neil" <nos...@nospam.netwrote:
>Can I get the name of a procedure from within the procedure? In my error
handler, I write the error to an error table. I'd like to write the name
of
the procedure that's writing the error. But, rather than customizing each
error handler with the procedure name, it would be nice to be able to
call a
system variable or function that gives me the procedure name and module
name. Is that possible?

It would be a couple of hours work I suppose to write code that would
put into each procedure as line two and three:
Dim VBProcedureName$
VBProcedureName = "Module13:Temp"
for Procedure "Temp" in Module 13.
or whatever. I suppose one would want the Module13 bit to
differentiate among various Temp private subs in various Modules.

But to what purpose?
I write my own error handling code only when I feel I need to be sure
that nothing non-VBAish is left dangling. A low level file handle is
one of these. Somewhere in the mists of time when Access was only a
gleam in the Wicked Witch of the West's eye I learned that these
should be closed. So when I open one, I do it within error handling
that will close it on error.
But almost none of my modules require that kind of fail-safe garbage
deletion. And almost none has its own error-handling.
Yes, I know, thousands of developers who write code superior to mine
are going to protest here. Such is life.

Having run the code once, then what? If we run it again we'll get
Dim VBProcedureName$
VBProcedureName = "Module13:Temp"
Dim VBProcedureName$
VBProcedureName = "Module13:Temp"

which will raise a compile error. So now we have to be sure the lines
are not already there. And if we change the name of a procedure ... I
suspect that ifs just keep rolling on here.


Nov 17 '07 #8

"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:47***********************@per-qv1-newsreader-01.iinet.net.au...
Unfortunately, VBA does not expose the name of the executing procedure,
nor
the name of that module.

In case you are not aware, there is a great little utility you can
download
from:
www.mztools.com
Ta for the tip on that utility. Just being able to clear the immediate
window with a single click is useful :)
Nov 19 '07 #9
Does it have the ability to *close* the Immediate window with a single
click? I've always hated how you can press Ctrl+G to open the Immediate
window; but pressing Ctrl+G a second time doesn't close it. I hate having to
close it with the mouse all the time. That would be a great feature if it
had it!
"Deano" <de***@mailinator.comwrote in message
news:5q************@mid.individual.net...
>
"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:47***********************@per-qv1-newsreader-01.iinet.net.au...
>Unfortunately, VBA does not expose the name of the executing procedure,
nor
>the name of that module.

In case you are not aware, there is a great little utility you can
download
>from:
www.mztools.com

Ta for the tip on that utility. Just being able to clear the immediate
window with a single click is useful :)


Nov 19 '07 #10

"Neil" <no****@nospam.netwrote in message
news:uw**************@nlpi061.nbdc.sbc.com...
Does it have the ability to *close* the Immediate window with a single
click? I've always hated how you can press Ctrl+G to open the Immediate
window; but pressing Ctrl+G a second time doesn't close it. I hate having
to
close it with the mouse all the time. That would be a great feature if it
had it!
No it doesn't do that. Given that Access doesn't seem to support the
feature it seems unlikely that this toolkit would either.
Nov 19 '07 #11
Well, I was hoping for a miracle. You can't blame a fellow for dreaming, can
you? :-)

"Deano" <de***@mailinator.comwrote in message
news:5q************@mid.individual.net...
>
"Neil" <no****@nospam.netwrote in message
news:uw**************@nlpi061.nbdc.sbc.com...
>Does it have the ability to *close* the Immediate window with a single
click? I've always hated how you can press Ctrl+G to open the Immediate
window; but pressing Ctrl+G a second time doesn't close it. I hate having
to
>close it with the mouse all the time. That would be a great feature if it
had it!

No it doesn't do that. Given that Access doesn't seem to support the
feature it seems unlikely that this toolkit would either.


Nov 19 '07 #12

"Neil" <no****@nospam.netwrote in message
news:gq***************@nlpi070.nbdc.sbc.com...
Well, I was hoping for a miracle. You can't blame a fellow for dreaming,
can
you? :-)
Nah, guess not. Useful download though, haven't tried out all the stuff but
being able to drop in pre-written error handlers etc is useful. I tested to
make sure it wouldn't screw anything up and so far it looks like it works
just fine.
Nov 19 '07 #13
I just have error handlers stored in files, and I drop them in using Insert
| File. But being able to customize the error handler according to the proc
name would be useful.

"Deano" <de***@mailinator.comwrote in message
news:5q************@mid.individual.net...
>
"Neil" <no****@nospam.netwrote in message
news:gq***************@nlpi070.nbdc.sbc.com...
>Well, I was hoping for a miracle. You can't blame a fellow for dreaming,
can
>you? :-)

Nah, guess not. Useful download though, haven't tried out all the stuff
but
being able to drop in pre-written error handlers etc is useful. I tested
to
make sure it wouldn't screw anything up and so far it looks like it works
just fine.


Nov 19 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vipul Pathak | last post by:
Hello Friends ! I have the Following Code, that Executes a Stored Procedure and Attempt to read a Returned Integer Value from the StoredProc. But It gives Error ... ADODB.Command (0x800A0BB9)...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
2
by: Patrick Olurotimi Ige | last post by:
When i run the code below with stored proc :- I get only the first table results :-"templates" even if i fill the dataset with another table for example category,pages etc.. Any ideas? ...
6
by: Uday | last post by:
Hi everyone, I have a ASP page that triggers a db-side stored procedure. At the end of the procedure, it spits out a log file, that this ASP page reads and displays for the users. But the...
2
by: scotdb | last post by:
I'm trying to get the SQLERRMC info from the SQLCA into my SP so that I can use the information it provides. I'm successfully getting the SQLCODE and SQLSTATE and so added the SQLERRMC to the...
6
by: Ronchese | last post by:
Hello, is there any way to get the name of the current running procedure? For example: Public Sub Test( ) 'do something '...
0
by: aarnan | last post by:
I have two SqlDataSources that use two different stored procedures that take parameters to populate two controls, one dependant on an element of the other. The first data source,...
2
by: Andrew Cooper | last post by:
Greetings, I'm creating a website using ASP.NET. In creating my DAL I've got a Table Adapter that I've set up to use an existing Stored Procedure from an SQL Server 2000 database. However,...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.