VBA: Get the name of the clicked control

Hi,

With a userform, I'd like to get the name of the clicked control automatically.
So for:

  Private Sub LeftHeaderBox2_Click()
    Set HeaderBox = Me.LeftHeaderBox2: Call FillProposalHeaderBox(HeaderBox)
 
   ' What can I replace 'Me.LeftHeaderBox2' with?
   ' Would think 'Me.ActiveControl' -- but 'Msgbox Me.ActiveControl.Name' names the frame that the
  '  label is in.

 End Sub

The current situation is only inconvenient because I have tons of clickable labels in my userforms.

Thanks for your help.
Michael



bishop3000Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Antagony1960Commented:
Labels can't get the focus so it follows that they can never be the active control. The simplest way to do what you want is to use a module-wide string variable which you change in each label's click event, like so:

Dim sHeader as String

Private Sub lblHeader1_Click()
    sHeader = lblHeader.Caption
End Sub

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Antagony1960Commented:
It's a pity VBA doesn't have control arrays a la VB proper as that would make it a piece of cake.
0
Antagony1960Commented:
The only other method I can think of would rely on the labels being uniformly distributed and sized on their parent controls, in which case you could use the X and Y coordinates of the parent control's MouseDown event to calculate which label has been clicked on and set the string accordingly from a predefined array. But that might end up being as much work as setting the string in the labels' click events. And such a method would add a big overhead to the task if you ever needed to reposition the labels.
0
bishop3000Author Commented:
Hi Antagony1960,
Thanks for your feedback.
Definitely a moment of impotence for me...when the name of the control is in the procedure title itself but VBA won't tell me the control's name.
Regards,
Michael
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.