Setting the focus on a subform's Tab

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ericks
    New Member
    • Jul 2007
    • 74

    Setting the focus on a subform's Tab

    Setting focus is addressed through several questions on this forum but I find this so complicated that I need a taylormade answer.

    I have a tabbed main form called "Compounds" . On one of the tabs, called "Page75" is a tabbed subform called "RegistrationLa unchTogether" with one of its tabs called "Observatio ns". How do I set the focus on this tab from outside the main form?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Originally posted by Ericks
    Setting focus is addressed through several questions on this forum but I find this so complicated that I need a taylormade answer.

    I have a tabbed main form called "Compounds" . On one of the tabs, called "Page75" is a tabbed subform called "RegistrationLa unchTogether" with one of its tabs called "Observatio ns". How do I set the focus on this tab from outside the main form?
    Me.SubformName.Form.TabControlName.Pages("PageName")

    Comment

    • Ericks
      New Member
      • Jul 2007
      • 74

      #3
      Shouldn't the main form be mentioned also?

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by Ericks
        Setting focus is addressed through several questions on this forum but I find this so complicated that I need a taylormade answer.

        I have a tabbed main form called "Compounds" . On one of the tabs, called "Page75" is a tabbed subform called "RegistrationLa unchTogether" with one of its tabs called "Observatio ns". How do I set the focus on this tab from outside the main form?
        The following code will Set Focus to the RegistrationLau nchTogether SubForm on Page 75 outside the context of the Compounds Form. It assumes the Tab Control on Compounds is named TabControl. This is all I had time for at the moment:
        [CODE=vb]Forms!Compounds !TabControl.Pag es!Page75.Contr ols!Registratio nLaunchTogether .SetFocus[/CODE]

        Comment

        • Ericks
          New Member
          • Jul 2007
          • 74

          #5
          Originally posted by ADezii
          The following code will Set Focus to the RegistrationLau nchTogether SubForm on Page 75 outside the context of the Compounds Form. It assumes the Tab Control on Compounds is named TabControl. This is all I had time for at the moment:
          [CODE=vb]Forms!Compounds !TabControl.Pag es!Page75.Contr ols!Registratio nLaunchTogether .SetFocus[/CODE]

          Ok, that I assume will put the focus on the subcontrol. But I need to go one step further, namely to put the focus on the subcontrol's tab called "Observatio ns"

          Comment

          • Ericks
            New Member
            • Jul 2007
            • 74

            #6
            Originally posted by Ericks
            Ok, that I assume will put the focus on the subcontrol. But I need to go one step further, namely to put the focus on the subcontrol's tab called "Observatio ns"
            ADezii, your code worked in that it set focus to the tabbed subform. That's already great. But I need to go as said one step further, to a tab on that subform
            So just to put all the objects together:

            Mainform: Compounds
            Tab control of Mainform: TabCtl16
            Tab of Mainform: Page75
            Subform: RegistrationLau nchTogether
            Tab control of Subform: TabCtl0
            Tab of Subform: Observations

            So what should I add to your code to set the focus on Observations outside the context of the Compounds Form

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by Ericks
              ADezii, your code worked in that it set focus to the tabbed subform. That's already great. But I need to go as said one step further, to a tab on that subform
              So just to put all the objects together:

              Mainform: Compounds
              Tab control of Mainform: TabCtl16
              Tab of Mainform: Page75
              Subform: RegistrationLau nchTogether
              Tab control of Subform: TabCtl0
              Tab of Subform: Observations

              So what should I add to your code to set the focus on Observations outside the context of the Compounds Form
              It hasn't been tested, but something in the order of:
              [CODE=vb]
              Forms!Compounds !TabCtl16.Pages !Page75.Control s!R egistrationLaun chTogether.Form !TabCtl0.Pages! Observations.Se tFocus
              [/CODE]

              Comment

              • Ericks
                New Member
                • Jul 2007
                • 74

                #8
                Originally posted by ADezii
                It hasn't been tested, but something in the order of:
                [CODE=vb]
                Forms!Compounds !TabCtl16.Pages !Page75.Control s!R egistrationLaun chTogether.Form !TabCtl0.Pages! Observations.Se tFocus
                [/CODE]
                With this code the main form opens but it doesn't go to tab Page75. It stays on the first Tab. But when I click on tab Page75 the focus on the Subform is on the Observations tab. So I added your first code as second line and now it works. It looks like this:

                Forms!Compounds !TabCtl16.Pages !Page75.Control s!RegistrationL aunchTogether.F orm!TabCtl0.Pag es!Observations .SetFocus
                Forms!Compounds !TabCtl16.Pages !Page75.Control s!RegistrationL aunchTogether.S etFocus

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Originally posted by Ericks
                  With this code the main form opens but it doesn't go to tab Page75. It stays on the first Tab. But when I click on tab Page75 the focus on the Subform is on the Observations tab. So your code did something "behind the scenes" but stayed at the first tab.
                  Here is a Method that I have tested and it does, in fact, work:
                  1. Assign a Hot Key (&O) combination to the Observations Tab (set the Name = &Observation s).
                  2. The following code will activate that Tab (Observations) on the Sub-Form:
                    [CODE=vb]
                    Forms!Compounds !TabCtl16.Pages !Page75.Control s!RegistrationL aunchTogether.S etFocus
                    SendKeys "%O"
                    [/CODE]
                  3. It is not very elegant, but it does work.

                  Comment

                  • Ericks
                    New Member
                    • Jul 2007
                    • 74

                    #10
                    Originally posted by ADezii
                    Here is a Method that I have tested and it does, in fact, work:
                    1. Assign a Hot Key (&O) combination to the Observations Tab (set the Name = &Observation s).
                    2. The following code will activate that Tab on the Sub-Form:
                      [CODE=vb]
                      Forms!Compounds !TabControl.Pag es!Page75.Contr ols!Registratio nLaunchTogether .SetFocus
                      SendKeys "%O"
                      [/CODE]
                    3. It is not very elegant, but it does work.
                    As written above, this is what I did and now it seems to work:

                    1. Forms!Compounds !TabCtl16.Pages !Page75.Control s!Reg istrationLaunch Together.Form!T abCtl0.Pages!Ob serva tions.SetFocus

                    2. Forms!Compounds !TabCtl16.Pages !Page75.Control s!Reg istrationLaunch Together.SetFoc us

                    Important is that it works but I'm curious tio know why it needs the two lines...

                    So thanks a lot. It worked. Highly appreciated.

                    Eric

                    Comment

                    • Jim Doherty
                      Recognized Expert Contributor
                      • Aug 2007
                      • 897

                      #11
                      Originally posted by ADezii
                      Here is a Method that I have tested and it does, in fact, work:
                      1. Assign a Hot Key (&O) combination to the Observations Tab (set the Name = &Observation s).
                      2. The following code will activate that Tab (Observations) on the Sub-Form:
                        [CODE=vb]
                        Forms!Compounds !TabCtl16.Pages !Page75.Control s!RegistrationL aunchTogether.S etFocus
                        SendKeys "%O"
                        [/CODE]
                      3. It is not very elegant, but it does work.
                      Hi Dez,

                      Just offering my two penneth FWIW to the posting (you might want to include a mention to this in the 'howto' article 'referring to tab controls' I've just read on here if you consider it helpful?)

                      Tab controls form part of a form object so you can refer to them explicitly by name including the pages of a tab....

                      Me!SubformName! RegistrationLau nchTogether.Set Focus
                      or
                      Me!SubformName. form.Registrati onLaunchTogethe r.SetFocus
                      or
                      Me!SubformName. form!Registrati onLaunchTogethe r.SetFocus

                      does what the poster requires so drilling down the hierachy through to the controls collection is not actually needed. In addition it also caters for the situation where they 'might' delete a tab page at some point causing the index number to shift. I've seen several postings where they are hard coding the index number in, and of course that can alter things significantly at runtime with the wrong page being selected because there hitherto absolute reference has been broken.

                      I agree with the poster referring to them is confusing to the newbie

                      Regards

                      Jim :)

                      Comment

                      • ADezii
                        Recognized Expert Expert
                        • Apr 2006
                        • 8834

                        #12
                        Originally posted by Jim Doherty
                        Hi Dez,

                        Just offering my two penneth FWIW to the posting (you might want to include a mention to this in the 'howto' article 'referring to tab controls' I've just read on here if you consider it helpful?)

                        Tab controls form part of a form object so you can refer to them explicitly by name including the pages of a tab....

                        Me!SubformName! RegistrationLau nchTogether.Set Focus
                        or
                        Me!SubformName. form.Registrati onLaunchTogethe r.SetFocus
                        or
                        Me!SubformName. form!Registrati onLaunchTogethe r.SetFocus

                        does what the poster requires so drilling down the hierachy through to the controls collection is not actually needed. In addition it also caters for the situation where they 'might' delete a tab page at some point causing the index number to shift. I've seen several postings where they are hard coding the index number in, and of course that can alter things significantly at runtime with the wrong page being selected because there hitherto absolute reference has been broken.

                        I agree with the poster referring to them is confusing to the newbie

                        Regards

                        Jim :)
                        Hell Jim, your two penneth is always welcome and definately appreciated.

                        Comment

                        • Ericks
                          New Member
                          • Jul 2007
                          • 74

                          #13
                          Originally posted by ADezii
                          Hell Jim, your two penneth is always welcome and definately appreciated.
                          whilst this newbie witnesses the discussion in a state of amazed admiration and profound bewilderment exclaiming to the Gods of VBA, not worthy, not worthy...

                          Great job you guys. I'm glad there is this forum.

                          Comment

                          • ADezii
                            Recognized Expert Expert
                            • Apr 2006
                            • 8834

                            #14
                            Originally posted by Ericks
                            whilst this newbie witnesses the discussion in a state of amazed admiration and profound bewilderment exclaiming to the Gods of VBA, not worthy, not worthy...

                            Great job you guys. I'm glad there is this forum.
                            We are just as glad to have you aboard.

                            Comment

                            • Jim Doherty
                              Recognized Expert Contributor
                              • Aug 2007
                              • 897

                              #15
                              Originally posted by Ericks
                              whilst this newbie witnesses the discussion in a state of amazed admiration and profound bewilderment exclaiming to the Gods of VBA, not worthy, not worthy...

                              Great job you guys. I'm glad there is this forum.
                              You're very welcome Ericks,

                              As for profound bewilderment I remember feeling that way once many years ago when I first picked up a mouse pointing it at the monitor expecting to change channels :)

                              Jim :)

                              Comment

                              Working...