bishop3000
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(Head erBox)
' 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
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(Head
' 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
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