Link to home
Start Free TrialLog in
Avatar of bishop3000
bishop3000Flag for United States of America

asked on

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



ASKER CERTIFIED SOLUTION
Avatar of Antagony1960
Antagony1960

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Antagony1960
Antagony1960

It's a pity VBA doesn't have control arrays a la VB proper as that would make it a piece of cake.
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.
Avatar of bishop3000

ASKER

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