PDA

View Full Version : Solved: Dynamically Adding a Page to a TabStrip



Annodomini2
01-27-2006, 02:27 AM
Hi all,

I am new to VBA and have been following tutorials posted on the web to create some automated word documents to make life a little easier.

However I appear to have hit on a stumbling block, I am attempting to create a form where it has a TabStrip defined with the Controls already added and then with that form from a previous form define the number of pages I wish to have in the Tabstrip on the next form.

E.g. Each page contains information about an object (car, plane whatever...), but you only know how many objects you have from the previous Form, therefore I wish to add pages upto the number of objects.

Is this possible? I am a C programmer and my VB/VBA knowledge is very limited and I am struggling a little with the syntax.

Hope someone can help.

TIA
Anno

Killian
01-27-2006, 03:01 AM
Hi and welcome to VBAX :hi:

The object model for forms follows the same principle as the Word specific objects, in that the various elements are referenced though collections:
So where UserForm1 has a tabstrip called "TabStrip1" - it will be in the form's Controls collection and can be referred to by nameUserForm1.Controls("TabStrip1")However, if you are already in the code module for the form, you can refer to the TabStrip1 object directly.

Similarly, the TabStrip object has a "Tabs" collection we can access and add members using the standard collection method "Add".TabStrip1.Tabs.Add ("Tab Caption")You can now refer to the new tab by name or index, relative to the Tabs collectionTabStrip1.Tabs("Tab Caption").Remove

'or

TabStrip1.Tabs(TabStrip1.Tabs.Count - 1).Caption = "Last tab"

Annodomini2
01-28-2006, 09:49 AM
Thanks for the rapid response,

I am now adding tabs as and when necessary! :)