473,887 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ 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 9221
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_frmInvoic e"
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******** *********@newss vr21.news.prodi gy.net...
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 adhClipboardSet Text(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 adhTestClipboar d()
' 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 adhReportClipbo ardError(ByVal intError As Integer)
' Reports an error received from the clipboard
' From Access 97 Developer's Handbook by Litwin, Getz, and Gilbert.

Public Function adhClipboardGet Text() 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*********@Se eSig.Invalidwro te 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_frmInvoic e"
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******** *********@newss vr21.news.prodi gy.net...
>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*******@Fortu neJames.com
Nov 16 '07 #5
On Fri, 16 Nov 2007 16:31:55 -0500, "James A. Fortune"
<MP*******@Fort uneJames.comwro te:
>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*******@Fort uneJames.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:T emp"
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:T emp"
Dim VBProcedureName $
VBProcedureName = "Module13:T emp"

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******** *************** ***********@i37 g2000hsd.google groups.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:T emp"
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:T emp"
Dim VBProcedureName $
VBProcedureName = "Module13:T emp"

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*********@Se eSig.Invalidwro te 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***@mailinat or.comwrote in message
news:5q******** ****@mid.indivi dual.net...
>
"Allen Browne" <Al*********@Se eSig.Invalidwro te in message
news:47******** *************** @per-qv1-newsreader-01.iinet.net.au ...
>Unfortunatel y, 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

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

Similar topics

3
22933
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) Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. /C4U/DBOutputParameterTest.asp, line 25
2
5470
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
2
2379
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? Store procedure below:- ------------------------
6
1960
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 problem is that the database-stored Proc could take anything between 10 secs - to - 10 mins. I dont want the page to time out . Is there a way, like the airlines websites do, where I can just show an animated gif while the procedure runs and redirect...
2
3706
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 code which obtains these. It doesn't seem to work however - create procedure dbair001.sp001testerr ( ,OUT p_sqlstate CHAR(5) ,OUT p_sqlcode INTEGER ,OUT p_sqlerrmc VARCHAR(70)
6
2608
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
1404
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, PreBuyDataSource is bound to PreBuyDetailsView control and its parameters come from the session or request. The stored procedure will always only find one row, and I found the DetailsView control to be convenient. The second data source, BudgetDataSource is...
2
1777
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, when I select the stored procedure I want to use the fields that are returned do not show up in the listbox for that stored procedure. If I continue and attempt to finish the Table Adapter I get the following error (even though the Adapter is...
1
4938
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 order, Input field and a submit button. The Category name is being fetched from the oracle db along with the corresponding Category order. In the corresponding input field (text box) the user enters a new category order which gets stored in...
0
9957
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10771
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10434
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9593
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7143
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4633
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.