Control addressing on subforms

J

JB

I have a subform that contains a bunch of controls (aka color-coded boxes)
that I want to be able to assign OnDblClick actions to. Other data defines
color/position of my boxes, but I need to programmaticlly modify what happens
during the OnDblClick of each box.

Ideally, I wanted to write 1 macro that I can assign to the control(s) as
VBA is rearanging the subform. The problem I am having is:

How can I get the Control Name off of the sub-form? I have tried versions of:
CurrentObjectName = Application.CurrentObjectName and
Set ctl = Screen.ActiveControl

but I keep getting pointed to the main form not the subform. Any
suggestions on how to tell which control has been clicked on?


Thanks in advance.
 
A

Allen Browne

Use Form.ActiveControl instead of Screen.ActiveControl.

Pass a reference to the subform into your generic procedure.

Example:
Function DoSomething(frm As Form)
Debug.Print "You dbl-clicked " & frm.ActiveControl.Name
End Function

Call it by setting the text box's On DblClick property to:
=DoSomething([Form])
or if you prefer to use an event procedure:
Private Sub Text1_DblClick(Cancel As Integer)
Call DoSomething(Me)
End Sub
 
Top