By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,012 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Accessing Tabs on a Tab Control

ADezii
Expert 5K+
P: 8,616
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 Article
Share on Google+
4 Comments


100+
P: 157
Thank you :)
I bookmarked this thread
Aug 20 '07 #2

P: 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 ...
Mar 17 '08 #3

NeoPa
Expert Mod 15k+
P: 31,310
Smith, this question needs to be asked in the technical forum. This section is for Articles only.

Administrator.
Aug 5 '08 #4

Expert 100+
P: 374
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. me.controlname
  3.  
  4.  
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.
Aug 5 '08 #5