Get name of current sub/function OR name of last label clicked

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Wotcha,

Situation: Access form with a profusion (some might even say a cornucopia)
of text labels (which appear as hyperlinks thanks to the simple trick of just
putting a space in the hyperlink address property - thanks to someone else
for that one). When the user clicks one of these labels, a popup form which
displays various helpful comments from yours truly to help the poor sap fill
out a tax return. The onclick function looks like this:

Private Sub lblHelpDonationsToExemptOrganisations_Click()

displayHelp Replace("lblHelpDonationsToExemptOrganisations_Click", "_Click",
"")

End Sub

and the function it calls, displayHelp, looks like this:

Function displayHelp(labelClicked As String)

'''''copy the contents of a text file to another file''''
setCurrentInfoText getDbPath & "macrosFiles\abbreviatedHelp\" & labelClicked
& "helptext.txt"
'''''open a popup form which reads the text from the copied text file and
display it''''
DoCmd.OpenForm "userInfoDisplay"
End Function

....which, in basic terms, just shows a certain text file, the filename of
which is obviously based on the name of the label.

There's dozens of these help labels for each userform, and lots of userforms
thanks to the fact that the country I'm working in has a tax system which,
despite recent renovation, can be likened to something out of at least a
Kafka novel, if not Dante's Inferno. If I was American I'd call it cruel and
unusual. Anyways, what I want to do is alleviate the necessity of copying
and pasting the name of the sub each time I write a help label onclick
function (thus saving myself from the rigours of carpal tunnel syndrome).
The way I see it, that would involve one of three things:

1. Programmatically determining the name of the sub that is currently being
executed, like this:

Private Sub lblHelpDonationsToExemptOrganisations_Click()

displayHelp Replace(THENAMEOFTHISSUB, "_Click", "")

End Sub

or...

2. Programmatically determining the name of the last label to be clicked,
like this:

Private Sub lblHelpDonationsToExemptOrganisations_Click()

displayHelp Replace(THENAMEOFTHELASTLABELCLICKED, "_Click", "")

End Sub

....or

3. Something I'm not clever enough to think of.

Me.ActiveControl does not cut the mustard - it doesn't recognise labels and
just gives you the name of the currently active button or textbox or whatever
(apparently considering labels to be untouchable out-castes beneath it's
notice, relegating them to the level of pond scum or perhaps amoebas). I've
spent hours scrolling through the object browser and this group and Googling,
looking for other likely candidates, but no joy.

Any ideas will be gratefully received. Probably pathetically gratefully
received, actually. Thanks, G ;)
 
Hi,


we can't put our hand on the "call stack" (the UI exists, in the VBE, View |
Call Stack ... (enabled if VBA is running (well, stop in debug)), so 1 is
out of question (at least, automatically),

Screen.Previous control may be what you seek

otherwise, you have to track yourself the name:


Private Sub whaterver_click( )

Const theName As String = "whatever_Click( )"


.... use the constant theName ...


End Sub




That required "collaboration", indeed, I mean, you forgot to supply
"theName", you are cooked.... but with Option Explicit, that should not be
"that" hard. Furthermore, using const insure you that you don't re-use the
variable name for other purpose, inside that sub (among other materialist
benefits liked to speed of execution)



Hoping it may help,
Vanderghast, Access MVP




"Ganeth"
 
Thanks Michel,

I've been looking into various methods since I posted this question, and
getting the name of the procedure you're currently in is not a trivial matter
even in normal VB. Any way that might be possible with Access Forms would
probably involve a lot of effort for very little gain. The easiest way to
reference the name of your function from within that function is still Ctrl+C
then Ctrl+V!

I haven't had any luck getting Screen.PreviousControl to fly - it just
produces errors.

Thank you for your help, though - it's good to know that I haven't missed an
easy method of achieving this.

Cheers,

G
 
Back
Top