Add Page to TabControl in VBA

  • Thread starter Thread starter SFatz
  • Start date Start date
S

SFatz

I would like to dynamically add pages to a tab control based on data in one
of my tables.
I am using the following command in the Form_Load event:
Me.tabFilter.Pages.Add (where tabFilter is the name of the TabControl)
VB protests claiming that I "must be in Design view to create or delete
controls."
The help seems to indicate that I should be able to do this with VB. (is
this VB, and not VBA??)
If not, then why add the .Add method?

How do I dynamically add pages to the tab control with VBA?

Thanks in advance for the help.
 
You can open the Form (but not visible) in DesignView by code and then use
the Add Method to add a Page to the Tab Control.

However, it is much easier to create as many Tab Pages as you need in
DesignView first and simply use code to show / hide each Page as appropriate
when the Form is running. Changes in the Visible Property of the Pages can
be done in "run" mode and you don't need to open the Form in Design view.
 
Thanks for the response. Changing the visibility of the tab is what I
eventually did. But, since I like to anticipate future issues, was looking
for a dynamic solution whereas I don't have to predetermine how many topics
I will need in the tabs.

I assume that you refer to the following command for opening the form in
Design view.
DoCmd.OpenForm "frmFormToOpen", acDesign

My thanks again to you (and all the other MVPs out there) for your
assistance.
 
Back
Top