Working with a tab control

  • Thread starter Thread starter frank
  • Start date Start date
F

frank

Hello,

I have a tab control with 5 pages. How do I get the page
name that is active? also, how would I loop through all
of the controls on a particular page only?

Thanks in advance
 
frank said:
Hello,

I have a tab control with 5 pages. How do I get the page
name that is active? also, how would I loop through all
of the controls on a particular page only?

Thanks in advance

The Value proprty of the tab control itself is equal to the PageIndex of
the current page. So to get the name of that page, you could do this
(assuming the code is running on the form containing the tab control):

Dim strPageName As String

With Me.tabMyTabControl
strPageName = .Pages(.Value).Name
End With

Each page object has its own Controls collection, which you can loop
through. The following will print the names of all controls on the
current page of tabMyTabControl:

Dim ctl As Control

With Me.tabMyTabControl
For Each ctl in .Pages(.Value).Controls
Debug.Print ctl.Name
Next ctl
End With
 
Thanks for your reply. Worked great. One last question.
When I'm looping throught each page objects controls, how
would I assign a reference to that control?

Each of my tab pages contain a list box. From another
form I wanted to set a referance to the list box on the
active tab page. My thinking was to loop through the
active page to get a reference to the list box.

Thanks
 
frank said:
Thanks for your reply. Worked great. One last question.
When I'm looping throught each page objects controls, how
would I assign a reference to that control?

Each of my tab pages contain a list box. From another
form I wanted to set a referance to the list box on the
active tab page. My thinking was to loop through the
active page to get a reference to the list box.

All the controls on the tab pages are also members of the form's
Controls collection, so the easiest way -- if you know the name of the
control you want to reference -- is to just set your reference to the
control by name via a reference to the form. So you could always do
this:

Dim frm As Form
Dim ctl As Control

Set frm = Forms!MyForm

Select Case frm!tabMyTabControl.Value
Case 0 : Set ctl = frm!lstListboxA
Case 1 : Set ctl = frm!lstListboxB
Case 2 : Set ctl = frm!lstListboxC
Case 3 : Set ctl = frm!lstListboxD
End Select

On the other hand, if the listboxes are named in such a way that their
names can be constructed from the page index (or page name), then you
could do something like this:

Dim ctl As Control

With Forms!MyForm
Set ctl = .Controls("lstListbox" &
..Controls("tabMyTabControl").Value)
End With

Failing any of the above, if there can be only one list box on any of
the tab pages, you could loop through the controls on the tab page
looking for one with .ControlType = acListBox. But that seems to me
like more trouble than it's worth.
 
Back
Top