Accessing Tabs on a Tab Control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #1

    Accessing Tabs on a Tab Control

    One frequently asked question at TheScripts is how to set focus/make active a specific Tab on a Tab Control other than clicking on it. Before I provide the answer, I feel as though a little summary information would be most helpful.

    __1. An individual Tab on a Tab Control is actually a Page Object. For this discussion, we will use the terms Tab/Page interchangeably , however.
    __2. Each Page Object is a member of the Pages Collection which includes all Pages on a Tab Control.
    __3. Each Page Object provides a Controls Collection which references all Controls on a specific Tab/Page.
    __4. Now that you are thoroughly confused, there are basically 5 Methods for referring to an individual Tab on a Tab Control. We will be using the SetFocus Method to demonstrate this point.

    ASSUMPTIONS:
    __1. Tab Control name: TabCtl1
    __2. Number of Tabs/Pages: 6
    __3. Tab/Page Captions: Page1, Page2, Page3, Page4, Page5, Page6
    __4. Tab/Page Names: pgeOne, pgeTwo, pgeThree, pgeFour, pgeFive, pgeSix

    Code:
    [B]Method 1:[/B]
    Me!TabCtl1.Pages(0).SetFocus - set Focus to the 1st Tab
    
    [B]Method 2:[/B]
    Me!TabCtl1.Pages!pgeThree.Setfocus - set Focus to 3rd Tab
    
    [B]Method 3:[/B]
    Me!TabCtl1.Pages("pgeFour").Setfocus - set Focus to 4th Tab
    
    [B]Method 4:[/B]
    Me!TabCtl1.Value = 4 - makes the 5th Tab active
    
    [B]Method 5:[/B]
    SendKeys "%a" - makes the 6th Tab active (a is a 'Hot Key' in the Caption of this Tab.
    NOTE: Should Tabs be added or deleted, your code may have to be modified in order to set Focus to the proper Tab
  • MrDeej
    New Member
    • Apr 2007
    • 157

    #2
    Thank you :)
    I bookmarked this thread

    Comment

    • smith1966
      New Member
      • Mar 2008
      • 3

      #3
      Fantastic Stuff ...
      I've been lokking for this info for ages.

      One other question tho ...

      How do I reference the controls on the individual pages.
      eg
      Within VBA ... How do I access access "Control-A" on "Page-3" If I have focus set to "Page-1" ?

      Thanks In Advance ...

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        Smith, this question needs to be asked in the technical forum. This section is for Articles only.

        Administrator.

        Comment

        • PianoMan64
          Recognized Expert Contributor
          • Jan 2008
          • 374

          #5
          Originally posted by smith1966
          Fantastic Stuff ...
          I've been lokking for this info for ages.

          One other question tho ...

          How do I reference the controls on the individual pages.
          eg
          Within VBA ... How do I access access "Control-A" on "Page-3" If I have focus set to "Page-1" ?

          Thanks In Advance ...
          They are all at the form level.

          Code:
          me.controlname
          since you have to have a unique name for each control on the form, that is how you reference each control on the form. It doesn't matter that it is in tab control.

          Hope that helps,

          Joe P.

          Comment

          Working...