TabStrip Control

J

Jaspar

I can't seem to find documentation on how to use the
TabStrip control in VBA. I have created a simple form with
a TabStrip control named tab. I have put a listbox in the
client region of tab1 and named it listbox.

During initialization of this form I would like to define
how many tabs the tabstrip control will have and the
caption of each tab - and this is easy:

Set MyTab = form.tab.Tabs.Add("tab1")
MyTab.Caption = "Number 1"

Then I want to populate the listbox with different items
dependant upon which tab I'm handling - and I don't know
how to access the listbox in the tabstrip control - I have
tried with:

Set MyListbox = MyTab.Tabs.Item(0)
MyListbox.AddItem "Item 1"

- but it doesn't work. Anybody knows how this works?
 
J

Jay Freedman

Hi, Jaspar,

The fundamental misunderstanding is that the listbox isn't a "child" of the
tabstrip. It's a separate object contained in the userform. You need to use
the tabstrip's _Change() procedure to empty and refill the listbox each time
the user clicks one of the tabs. What you refill it with will depend on
which tab was clicked, which is most easily determined by looking at the
tabstrip's .SelectedItem.Caption:

Private Sub TabStrip1_Change()
Select Case TabStrip1.SelectedItem.Caption
Case "A"
With ListBox1
.Clear
.AddItem "one fish"
.AddItem "two fish"
End With
Case "B"
With ListBox1
.Clear
.AddItem "red fish"
.AddItem "blue fish"
End With
Case Else
End Select
End Sub

In the UserForm_Initialize() procedure, you can simply fill the listbox with
the values that are appropriate for .Tabs(0), since that's the default tab.
 
J

Jaspar

Thanx J

Yeah - I was on a wrong track there, thanx for getting me
back on track. It works great now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top