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
NOTE: Should Tabs be added or deleted, your code may have to be modified in order to set Focus to the proper Tab
__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.
Comment