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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

programmatically refer to label control 1

Status
Not open for further replies.

Eupher

MIS
Jul 18, 2002
1,724
US
I'm building a form that has a large number of label controls that have the same code in the OnClick and OnDblClick events. The generic form of the code is like this:
Code:
Private Sub lbl1_Click()
Call SomeFunction(Me!lbl1)
End Sub
I would like to not hard-code the control name in the function argument; I would still obviously need to call the procedure in each control's click event, but I could just cut-and-paste the code without having to change the argument. If it was a textbox control, I would declare a control variable and set it to Screen.ActiveControl. But this doesn't seem to work with labels. Is there a method or property by which to refer to a clicked label? Thanks!

Ken S.
 
p.s. I looked at the CodeContextObject property, but that returns the form, not the control.

Ken S.
 
One workaround would be:

A transparent button can still have a focus and be an active control:

place this click event code behind a button named command1 on a form. Make a transparent button named command0

Command0.SetFocus
Dim ctlCurrentControl As Control
Dim strControlName As String
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.name
MsgBox strControlName

What this means is: Place transparent buttons over the label.

Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
Thanks for the tip, I will try that tomorrow.

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top