Control addressing on subforms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top