Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing Sub/Function Name into variable???

Status
Not open for further replies.

HiBoo

Programmer
Jan 11, 2000
88
CA
I've got an Error Handling routine that I call from my program sub's and function's. One of the routine's parameters ( a string) is the name of the sub or function from which it is called. For example...

Private Sub button1_OnClick()
On Error Goto HandleError

' code here

Exit_Gracefully:
Exit Sub
HandleError:
Call ErrorHandler("button1_OnClick", ...)
Resume Exit_Gracefully
End Sub

What I'd like to know is if I can reference the button1_OnClick string somehow so as I can copy and paste the function into each of my sub/function's without having to hardcode each one. It's very time consuming and I'm looking for a short cut!!!

Thanks for any help and or suggestions.
 
Hi HiBoo,

The following should do the trick:

CallErrorHandler (Me.ActiveControl.Name)

but only, I suppose, if there is only one function from each control.

As to how you know which event it is, well that's a different matter.

Hope this helps a bit though,

Jes
 
Thanks Jes, I tried that out actually and am always getting a NULL string returned. The ErrorHandler() is a function I've set up in a public module. It's parameters are...
(ModulName As String, ErrNum As Long, ErrDesc As String)

Is there maybe some kind of REFERENCE I'm missing because when I type in me.ActiveControl. ...I don't get a 'Name' option from the drop down list? FYI-I'm using MSAccess2000.

What I do with this information is populate a table on a network db that I can access to watch where errors occur when users run my program. Each user has a copy of the program on their local machines. The ErrorHandler() tells me the where/when/who/why/how. The Modulname is the only part I have to hard code because I can't get the actual name of the Function or Sub returned as you mentioned, using me.ActiveControl.Name. I suppose I'm out of luck for now but that's the name of the game!

Thanks for your input.
 
Me only refers to the FORMs things. Me.Name is the form which hase the focus. Me.ActiveControl is the name of the control which has the focus on the form which has the focus. In MANY circumstances (including error handling) no control has the focus. A way to do the process is to have each FORM activate event post it's "name" in a golbal variable. Similarly, each control can post it's name in a (different) golbal variable. Have your erro posting mechanisim reference these.

I have done a similar thing to provide a "Trace Log" for a few intractable problems where things went sadly (and badly) awry. For my problems, I set up a flag to control the trace process. When there was a problem, I logged ALL transitions of focus to a simple text file. Using one additional Global name, I added a module name. One more "field" and I got the value of a specific variable at the point of execution. Use raise error, it works "sorta' like a break point - without the hassle of stopping.
MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top