Using Name of Subroutine (or similar) as string inside that sub. (1 Viewer)

wiklendt

i recommend chocolate
Local time
Today, 21:19
Joined
Mar 10, 2008
Messages
1,746
Hi guys. i wanted to use the name of the subroutine/function that is running as a string in my error handler, but i don't know how to reference it.

what i hope to get is: when i get an error, let's say

Error #94: invalid use of null

i would prefer to have

cmdOpenReport_Click Error # 94: invalid use of null

instead BUT i don't want to have to manually change the "cmdOpenReport_Click" for each subroutine, hence finding the 'name' of the code using some VBA.

i normally (until i learn how to globalise my error handling - also so that i can change the app title in the message box title bar very easily!) just copy and paste "my" error handler over the access standard one, so i prefer not to be changing that value manually.

does anyone have an idea how to do this? it's possible i'd like to do this for other code not just subs (e.g., functions) and i don't know if it will make a difference if they are private/public either...

any ideas or nudges welcome :)
 

boblarson

Smeghead
Local time
Today, 04:19
Joined
Jan 12, 2001
Messages
32,059
Use MZ Tools to enter the error handler. It does it for you and will include the procedure name for you as well.
 

wiklendt

i recommend chocolate
Local time
Today, 21:19
Joined
Mar 10, 2008
Messages
1,746
niiiiiice.... i downloaded MZ tools some time ago but hadn't had the real motivation to install it (i hadn't gotten round to investigating its uses). just installed it now - love it! i really like how it can add a rem header too :)

thanks :)
 

boblarson

Smeghead
Local time
Today, 04:19
Joined
Jan 12, 2001
Messages
32,059
niiiiiice.... i downloaded MZ tools some time ago but hadn't had the real motivation to install it (i hadn't gotten round to investigating its uses). just installed it now - love it! i really like how it can add a rem header too :)

thanks :)

I LOVE MZ Tools and would not want to be without it. Go into the OPTIONS and see where the real customizing power lies. You can set it up to do a lot.

Also, I like this other free tool - SmartIndenter (as I hate trying to format my code manually, I run SmartIntender on everything when I'm done).
 

Zaeed

Registered Annoyance
Local time
Today, 21:19
Joined
Dec 12, 2007
Messages
383
Antoher way is to use generic error handling code.. But have a variable at the top of each sub/function that contains the procedure name.

Code:
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
 
subName = Command0_Click

then in your error code just reference subName
 

boblarson

Smeghead
Local time
Today, 04:19
Joined
Jan 12, 2001
Messages
32,059
Antoher way is to use generic error handling code.. But have a variable at the top of each sub/function that contains the procedure name.

Code:
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
 
subName = Command0_Click

then in your error code just reference subName
Actually you would need Command0_Click to be in quotes in this example. But using MZ-Tools to set it, you don't need to do that and all you do is push a button to set an error handler in place with the name and all. It doesn't require you to do anything. So, the MZ-Tools is using some way of getting the name, but instead of re-inventing the wheel, if possible - use the existing tool.
 

Zaeed

Registered Annoyance
Local time
Today, 21:19
Joined
Dec 12, 2007
Messages
383
Sounds like I might need to take a look at MZ-Tools..

Do modifications made using it work on a computer that doesn't have it installed.. meaning if I use it, then distribute .mde versions of my db, do the users need anything extra installed?
 

wiklendt

i recommend chocolate
Local time
Today, 21:19
Joined
Mar 10, 2008
Messages
1,746
Sounds like I might need to take a look at MZ-Tools..

Do modifications made using it work on a computer that doesn't have it installed.. meaning if I use it, then distribute .mde versions of my db, do the users need anything extra installed?

i've only just installed MZ-Tools in the last 30 minutes. i'm loving it already. from what i can tell, the modifications you set are to help write the code, not to 'enhance' the GUI that you're making for the FE of your DB.

it's like using clipboard to paste stuff into your NotePad txt file. people without the clipboard will still be able to read your .txt in their NotePad (or native app for that extension - like EditPad Pro, like i use).

:)
 

wiklendt

i recommend chocolate
Local time
Today, 21:19
Joined
Mar 10, 2008
Messages
1,746
Go into the OPTIONS and see where the real customizing power lies.

Yah, that's the first thing i did, and got it to make the error handler JUST the way i like it :)

and i also learnt how to change my project name! in VBA Editor, right click on any of the forms in the object viewer, then under "View Code" and "View Object" there is the "[current name of your project] Properties..." menu item. click on that, and the editable Project Name field is the thing that has first focus :)
 

Zaeed

Registered Annoyance
Local time
Today, 21:19
Joined
Dec 12, 2007
Messages
383
:O

I wish i'd been using this from the start.. This tool is brilliant..
 

Users who are viewing this thread

Top Bottom