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

Referring to control in an event of that control

Status
Not open for further replies.

rfoye

Programmer
Oct 15, 2004
40
US
Is there any way to refer to the properties (eg .Name) of a control inside the code for an event of that control?

For example, in the OnClick event of a label:
Code:
Private Sub lblDept_Click()
    Dim stName As String
    stName = <label>.Name
    Debug.Print stName
End Sub
Where <label> is something like ActiveControl (which doesn't work in my situation).

I'm trying to write re-usable code where I don't have to specify "lblDept", or whatever the name of the label is.

You'd think that Access would know what Control the event is in, but I haven't been able to find a way to reference it.

-------------------
Rob Foye
Database Management
Regions Bank
 
My senility is getting worse, but I recall the issue of self-name was covered here at some point. I have not been able to find it yet, and I may be mis-remembering, but I think there is a way to get the name of the control.

Hopefully someone who has better neuron firing will post something.

Gerry
My paintings and sculpture
 
Event procedure lblDept_Click is by definition assigned to Click event of lblDept control. Each of controls will have its own set of event procedures with name combining control name and event name.
What you could do is to call here another general procedure with lblDept (as control or string) as argument.
Another option is a custom class handling events by WithEvents declaration. In this case a variable declared with WithEvents will store given control. You could create as many instances of such class as you like, the price could be limitation of available events.

combo

combo
 
And what about this ?
stName = Screen.ActiveControl.Name

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
What I was looking for was the ActiveControl.Name, which, as I stated in my original post, did not work in my situation. I had no choice but to change the labels into text fields in order for them to be active controls.

-------------------
Rob Foye
Database Management
Regions Bank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top