Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Control addressing on subforms

Discussion in 'Information Technology' started by JB, Nov 12, 2005.

  1. JB

    JB
    Expand Collapse
    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.
     
  2. Loading...

    Similar Threads Forum Date
    How To Control The 5 Thieves? Questions and Answers Apr 7, 2016
    General Controlling Kaam (Lust) Hard Talk Apr 8, 2014
    USA Sikh Americans join Barack Obama in urging lawmakers on Gun Control Breaking News Mar 29, 2013
    Controversial SGPC Takes Control of Live Telecast at Bangla Sahib Hard Talk Feb 7, 2013
    USA Sikhs Join Gun Control Debate. Meet with Vice President Biden Breaking News Jan 16, 2013

  3. Allen Browne

    Allen Browne
    Expand Collapse
    Guest

    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

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "JB" <JB@discussions.microsoft.com> wrote in message
    news:69FFE5CA-5569-4197-9356-E9A995A79C93@microsoft.com...
    >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.
     

Share This Page