Can I get form name / routine name from Access?

Hi,

I’m using Access 2003.

I have the following line that I include in my ON ERROR routine:

    Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description, 
"cbPrintReport_Click")

As you see, I currently hard code the name of my routine in my error message 
so I can display it in the error message.

I have two questions.

1.  Is there a way I can get the name of the current routine from Access so 
I do not have to hard code it in each line?

2.  Is there a way I can get the current form / report name from Access so I 
do not have to hard code it in each line?

Ideally I would like to have the following lines of code in my ON ERROR 
routines:

    strFormInfo = FunctionToGetFormName & “ – “ & FunctionToGetRoutineName
    Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description, strFormInfo)

This way when I display the error message, I will automatically know which 
routine generated the error message.  The form name is really helpful when 
I’m in a sub-form.

If I can not do the above, I will setup a standard variable for the form 
name & routine name and then just set the variable to the appropriate value.

Thank you for your assistance.

Dennis

0
Utf
12/28/2009 1:26:01 AM
access.formscoding 7493 articles. 0 followers. Follow

7 Replies
767 Views

Similar Articles

[PageSpeed] 0

Access (VBA) doesn't expose the name of the currently executing procedure 
for you.

If the code is associated with a form (i.e. it's not in a stand-alone 
module) the name of the current form is Me.Name. You could pass this as an 
argument to your Dsp_Err_Msg() procedure.

Don't use Module.Name. That fails if you convert your database to an MDE.

There are some commercial add-ons that read the module/routine name, e.g.:
    http://www.everythingaccess.com/simplyvba-global-error-handler.htm

What I do is to use the same constant in the General Declarations section 
(top) of every module, but with its actual name, e.g.:
    Private const conMod = "Form_frmClient"
and then use conMod in all code. Even if you copy'n'paste code between 
modules, it stays right.

Then I use MzTools to drop the procedure name (and the whole error handler) 
into your code:
    http://www.mztools.com/v3/mztools3.aspx

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


"Dennis" <Dennis@discussions.microsoft.com> wrote in message 
news:FA977A73-0B1F-43E1-A6C2-BBB22AE49051@microsoft.com...
> Hi,
>
> I’m using Access 2003.
>
> I have the following line that I include in my ON ERROR routine:
>
>    Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description,
> "cbPrintReport_Click")
>
> As you see, I currently hard code the name of my routine in my error 
> message
> so I can display it in the error message.
>
> I have two questions.
>
> 1.  Is there a way I can get the name of the current routine from Access 
> so
> I do not have to hard code it in each line?
>
> 2.  Is there a way I can get the current form / report name from Access so 
> I
> do not have to hard code it in each line?
>
> Ideally I would like to have the following lines of code in my ON ERROR
> routines:
>
>    strFormInfo = FunctionToGetFormName & “ – “ & FunctionToGetRoutineName
>    Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description, strFormInfo)
>
> This way when I display the error message, I will automatically know which
> routine generated the error message.  The form name is really helpful when
> I’m in a sub-form.
>
> If I can not do the above, I will setup a standard variable for the form
> name & routine name and then just set the variable to the appropriate 
> value.
>
> Thank you for your assistance.
>
> Dennis
> 
0
Allen
12/28/2009 2:12:30 AM
Alen,

Once again, thanks for all of your assitance.  I greatly appreciate it!
l
-- 
Dennis

0
Utf
12/28/2009 2:57:01 AM
Allen,

One other question.


Can I add a "optional" fourth parameter to my Dsp_Err_Msg?

I would like to add Form Name as the fourth parameter of Dsp_Err_Msg.  
However, I don't want to have to stop and change all of my code right now in 
order to implement this change.  I would rather make the changes over a 
period of time.

I know I can create a second Dsp Err Msg routine with a different name and a 
fouth parameter, but I would like to know how to declare optional parameters.


-- 
Dennis


0
Utf
12/28/2009 3:03:01 AM
"Dennis" <Dennis@discussions.microsoft.com> wrote in message 
news:FA977A73-0B1F-43E1-A6C2-BBB22AE49051@microsoft.com...
> Hi,
>
> I’m using Access 2003.
>
> I have the following line that I include in my ON ERROR routine:
>
>    Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description,
> "cbPrintReport_Click")
>
> As you see, I currently hard code the name of my routine in my error 
> message
> so I can display it in the error message.
>
> I have two questions.
>
> 1.  Is there a way I can get the name of the current routine from Access 
> so
> I do not have to hard code it in each line?
>
> 2.  Is there a way I can get the current form / report name from Access so 
> I
> do not have to hard code it in each line?

In my standard error-logger, I use CodeContextObject.Name to get the name of 
the object for which the code is executing.  See the help-file entry (in the 
VB Editor environment) for CodeContextObject.  In Access 2003, at least, it 
gives an example of this.

-- 
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

0
Dirk
12/28/2009 3:28:01 AM
Function Dsp_Err_Msg(lngNumber As Long, strDescription As String, Optional 
strFormName As String)

Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description, Me.Name)

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


"Dennis" <Dennis@discussions.microsoft.com> wrote in message 
news:E1467ED0-E253-4BFE-8728-713F814F7D81@microsoft.com...
> Can I add a "optional" fourth parameter to my Dsp_Err_Msg?
>
> I would like to add Form Name as the fourth parameter of Dsp_Err_Msg.
> However, I don't want to have to stop and change all of my code right now 
> in
> order to implement this change.  I would rather make the changes over a
> period of time.
>
> I know I can create a second Dsp Err Msg routine with a different name and 
> a
> fouth parameter, but I would like to know how to declare optional 
> parameters. 

0
Allen
12/28/2009 4:05:30 AM
Dirk,

Thank your for your assitance.  I will look up your suggestion.


-- 
Dennis

0
Utf
12/28/2009 5:49:01 AM
Allen,

Once again, thank you for your assitance.

-- 
Dennis


0
Utf
12/28/2009 5:49:02 AM
Reply:

Similar Artilces:

Changing domain names
When I first set up sbs2003 I used companyweb as my domain name. How do I change it to my xyz.com domain? Also if anyone knows of any helpful tutorials on this subject it would really help. Thanks in Advance Take a look at: 822447 How to Modify an SMTP E-Mail Address by Using Recipient Policies http://support.microsoft.com/?id=822447 You'll need to ensure that the new domain (xyz.com) has MX records pointing to your router (which should then point to the mail server) or directly to the mail server. You'll most likely need to modify the default recipient policy and change t...

error: OBE-15502 Can only have 16000 per document
Hi, I tried to export data from oracle query builder to Excel sheet, got a error message: OBE-15502 Can only have 16000 per document Is there any way i can get more records(over 16000 or unlimited) in one sheet? thanks. -- JJ ...

How to tell if a form is open
I want to know how to return a value telling me whether or not a form is currently open. Something like this pseudo-code: If Forms![new appointment].Open = True Then 'send harry a box of chocolates' End If Cheers -- Nick Assuming Access 2000 or later: If CurrentProject.AllForms("new appointment").IsLoaded Then -- 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. "Nick Heath" <NickHeath@discussions.microsoft.com> wrote in messa...

Can't see 401(k) contribiltion total
I've set up a 401(k)accont. I transfer contribiltions to this 401(k)account from each paycheck. When I go to the 401 (k) account view, it shows all the informations such as transections and the account vallue ect., EXCEPT the total contribiltion. I want to know not only what my 401(k) vallue is, but how much money I have contribilt total or over a period of time as well. I find no place to see it. Anybody can help? I'm using Money2002 and 2004 Trial Verstion. Thanks a lot! ...

How can I print a selection in Outlook 2003?
How can I print just a selection of an email in Outlook 2003? The printer driver window is different from the one that comes up in Outlook Express. Thank you! You can do this for HTML formatted messages. Highlight your text, File-> Print... and select to print only the selection -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Service Pack 1 ----- "Murphie" <Murphie@discussions.microsoft.com> wrote in message news:92F39B50-B877-408A-AAA7-DF350B1D72ED@microsoft.com....

Can different editions of Publisher be used together?
If my son uses Publisher 2003 on a school computer, downloads his work to a flash drive, brings it home to edit on Publisher 2007, will he then be able to take the edited work back to the school computer to be used, or will it not be compatible? Stateparent wrote: > If my son uses Publisher 2003 on a school computer, downloads his work to a > flash drive, brings it home to edit on Publisher 2007, will he then be able > to take the edited work back to the school computer to be used, or will it > not be compatible? Publisher 2003 and 2007 share a common file format, so the sc...

Can't send/receive
anyone have a situation where all of sudden they can't send new messages or receive anything? I get a message when I click on "accounts" that says 'fatal error in outlook unable to complete operation" ...

Can not Customize Leads View
Hi I have tried to customize the Leads view, I tried to add a view and add some columns to it. The view is shown however I see only the name column. When I go back to the View customization, I see the columns I added. Published your customizations??? -- ---------------------- regards, Ilya Milshtein MBS Master, MBSCP, MCP Softline International www.softline.ru "alsap" wrote: > Hi I have tried to customize the Leads view, I tried to add a view and add > some columns to it. > The view is shown however I see only the name column. > When I go back to the View customi...

Can I change the "Applied Task Update Requests and Errors" view?
I really like this view in PWA 2007, but I would like to replace one column with another. Is this view customizeable? Randy -- Bad news, my friend. This view is not customizable, nor is the view shown in the Task Updates customizable (which many users wish it was). Hope this help. -- Dale A. Howard [MVP] VP of Educational Services msProjectExperts http://www.msprojectexperts.com http://www.projectserverexperts.com "We write the books on Project Server" "Randy Schmid" <RandySchmid@discussions.microsoft.com> wrote in message news:72FA34B5-...

Hyperlink value crashes Access
If I assign a hyperlink value to a cmd button or in code using the follow hyperlink method, using a link value like http://www.cookbookplus.com/Activate.aspx, the page is accessed [Internet Explorer] OK, but the Access app crashes every time. However, if I instead just target the main web site http://www.cookbookplus.com that page is opened AND Access does not crash. Crashes also occur if a hyperlink field is populated with http://www.cookbookplus.com/Activate.aspx Again, that page is opened in IE, but Access crashes. The targeted page is a simple, safe, publicly available...

Should be an easy but I can not figure it out!!
I have a text box where the user enters a date and it is assigned to variable txtDate. How to I convert that to the serial number of the date? Thanks for the help IIRC, you can use DATEVAL(String) to get the serial date. -- HTH, Barb Reinhardt "VinceW" wrote: > I have a text box where the user enters a date and it is assigned to variable > txtDate. How to I convert that to the serial number of the date? > > Thanks for the help Barb, Thanks for the quick reply, however I get the error "Sub or Function not defined" when trying...

Bulk attachments
I have a very long list of Images in a single folder that I want to attach to seperate fields in a table/form. Each record contains two images, which are named like this: W:\Foldername\Micromap Run 001 A.bmp =(1st record) W:\Foldername\Micromap Run 001 B.bmp =(1st record) W:\Foldername\Micromap Run 002 A.bmp =(2nd record) W:\Foldername\Micromap Run 002 B.bmp =(2nd record) W:\Foldername\Micromap Run 003 A.bmp =(3rd record) W:\Foldername\Micromap Run 003 B.bmp =(3rd record) and so on... Image A goes to field A Image B goes to field B Is there a way of doing this au...

can't uninstall exchange from cluster nodes
hi our client has several exchange clusters, and one of them is being retired. we have removed the exchange resources and the EVS and the server no longer appears in the organization and everything else there seems to be ok. we can't seem to uninstall exchange from either of the nodes. setup will start saying it's loading components then terminates with no error; happens on both nodes. both nodes are exchange 2003 sp1 on windows 2003. i did find the setup log; here is what it says, hope someone can shed some light on this (company info replaced with < >): [19:47:23] *...

Can't delete email #2
I'm am trying to help a friend who is using Outlook Express on W98, I cannot delete any messages from her in box. She has over 500 in there, which may be part of the problem. Any suggestions? Desperate! Mark Mark Ryan <m.ryan@earthlink.com> wrote: > I'm am trying to help a friend who is using Outlook Express > on W98, I cannot delete any messages from her in box. She > has over 500 in there, which may be part of the problem. > Any suggestions? The first suggestion is to ask in an Outlok Express newsgroup. The second suggestion is to delete Deleted Items.dbx and ...

CListCtrl
Hi, Does anybody know an easy of removing the black vertical tracking line that appears while resizing columns? I've been trying to prevent it through HDN_ENDTRACK / HDN_TRACK, but I wasn't successfull. Is there a specific flag that I can set to disable it instead? Thanks in advance for your time, Best regards, -Onur I can't imagine why you'd want to do that, but here's my suggestion: Override the CListrCtrl and CHeaderCtrl class, and have your listview control use your derived header control. In the header control class, handle the WM_SETCURSOR message and load a d...

Can Not Reply To Emails
Running Windows 7 Professional with latest version of WLM. I get email messages I can not reply to. The reply button is grayed out. For now I am forwarding them to my WinXP computer and then replying from that computer with OE6. Anybody have any ideas? -- <Bill> Brought to you from Anchorage, Alaska. The most obvious reason for not having an active Reply button is not having a mail account set up. --=20 Gary VanderMolen, Microsoft MVP (Mail) http://mvp.support.microsoft.com/default.aspx/profile/vandermolen "Bill Bradshaw" <bradshaw@gci.net>...

How can I rename a database table?
Hi I am working on a project that uses the MFC CDatabase and CRecordset classes to handle its interfacing with an Access database. It is necessary for the software to rename a table within existing user databases to ensure that they are valid for use with the new version of the software. As a result of my limited database and MFC knowledge I am having difficulty finding a way of renaming the table. I have tried using the following: try { theDataBase.ExecuteSQL( "RENAME oldTableName TO newTableName"); } catch( CDBException* e) { e->m_strError; } However, it results in th...

What is the quickest way to get an xml based dataset to add entries to SQL Server?
Because there is no 'datareader' involved, what is the most efficient way to get an XML based dataset to be added to an SQL server dataset? I would hate to have to create a new SQL connection and iterate through making "executenonquery" for each row in the dataset. That seems horribly in-efficient. I know of no other way to get an xml based dataset to push data to the database though. Any pointers? Thanks for any pointers, Peter Robbins Freelance Programmer C#/PHP "MurdockSE" <murdock@nc.rr.com> wrote in message news:1153922058.675709.165630@h48g2000cwc.go...

Sychronizing Report and Parameter Form
How can I get a Report to Open a Paramenter form with the same record referenced? I just can't seem to get it. I have tried everything! Can someone please help me with this. Thank you. On Mon, 14 Jan 2008 07:24:03 -0800, TotallyConfused wrote: > How can I get a Report to Open a Paramenter form with the same record > referenced? I just can't seem to get it. I have tried everything! Can > someone please help me with this. Thank you. A Parameter Form is a form into which you enter a query's parameters. The query is used as the report's record source. It nee...

how can I restore unsaved changes in excel #2
...

Can (or how can) I do this
Hello, My Access application tracks an employee's progress through a process similar to hiring. There are 5 steps in the process. I track 4 of the steps by counting the number of times a value appears in a date field for that step. The count is then displayed and used in a calculation. The 5th step is more complicated. The 5th step needs to determine if the employee has verified that he can access all the applications that he should have access to. My process tracking table has the first 4 dates. The application access info comes from a different table. This process trackin...

Can Not Connect to Exchange Server after Mailbox Move
I have 2 exchange servers. While logged into the domain, and at the location, I can log into the email system just fine. While remote VPN in, I can not access the server. I can ping the server, I can see all shares, and I can even access the printer and print from the exchange server. But I can not get to it with email. Any Ideas? Oh.. both exchange 5.5, both in the same site. Exchange Admin shows both sites just fine. is there a firewall with rules configured, in between the users vpn connection and the internal network? kmelillo@gmail.com wrote: > Oh.. both exchange 5.5, bot...

Display Date from Unbound Field in Form in a Query
Just had an issue that in 10 years of using Access never saw - just wondering if I just never encountered it or what... I have a form running a query, the user enters a date. The report needs to show the date - so the query has a field like this: report date: [Forms!]![frm_report]![txtReportDate] I had a problem exporting to Excel - seems the direct placement in the query led to characters that Excel could not understand. I actually had another date field from the form that I did a date add on, it worked fine. I eventaully put the form reference in a Format, the issue was gone. The...

Can not archive
I get the message "Error while archiving folder "Deleted Items" in store "mailbox-user name." Some items could not be copied. They were either moved or deleted, or access was denied. This only happend recently and only occurs with the deleted items. I can archive send and the inbox without a problem. Any suggestions? Thanks ...

can'not set or connect to an email account
This is a multi-part message in MIME format. ------=_NextPart_000_0010_01CAAC2C.BBDF6A00 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0011_01CAAC2C.BBDF9110" ------=_NextPart_001_0011_01CAAC2C.BBDF9110 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable I am triying to set an email account.I am vodafone mobile customer.Some = settings bloking my access to email service.I am not a professinal = computer user,following the the instractions but no luck.Can you help = me? Thank you. ------=_Nex...