By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,557 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

TheScripts Tip of the Week #3 - Accessing Tabs on a Tab Control

ADezii
Expert 5K+
P: 8,607
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

Expand|Select|Wrap|Line Numbers
  1. Method 1:
  2. Me!TabCtl1.Pages(0).SetFocus - set Focus to the 1st Tab
  3.  
  4. Method 2:
  5. Me!TabCtl1.Pages!pgeThree.Setfocus - set Focus to 3rd Tab
  6.  
  7. Method 3:
  8. Me!TabCtl1.Pages("pgeFour").Setfocus - set Focus to 4th Tab
  9.  
  10. Method 4:
  11. Me!TabCtl1.Value = 4 - makes the 5th Tab active
  12.  
  13. Method 5:
  14. 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
Mar 11 '07 #1
Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,271
Brilliant ADezii.
I changed the Page6 to Page6 then I made a copy of this in the Access Tutorials section (Accessing Tabs on a Tab Control).
I suggest you copy this link and store it somewhere, so that you can send people to it when appropriate (I certainly have).
I've also unstuck it as we decided a while back to 'unclutter' the stickies to allow members to see the new threads. I'll update the Tutorials sticky to reflect this.
Mar 12 '07 #2

ADezii
Expert 5K+
P: 8,607
Brilliant ADezii.
I changed the Page6 to Page6 then I made a copy of this in the Access Tutorials section (Accessing Tabs on a Tab Control).
I suggest you copy this link and store it somewhere, so that you can send people to it when appropriate (I certainly have).
I've also unstuck it as we decided a while back to 'unclutter' the stickies to allow members to see the new threads. I'll update the Tutorials sticky to reflect this.
NeoPa:
Thanks for the Update. You would think that by now I would know the difference between Bold (Page6) and Underline (Page6). Thanks for the Update, follow up, and correction.
Mar 12 '07 #3

NeoPa
Expert Mod 15k+
P: 31,271
No problem matey. I was just pleased that you'd put this together.
Mar 12 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.