Tab Control Add/Remove pages

AMWO

New member
Local time
Today, 17:00
Joined
Aug 18, 2008
Messages
6
Hello,
I have a form bound to a table, in the table I have a record with a number from 0 to 10.
Depending on that number from the record I want to show the TabControl with a number of pages equal to the number from the table + 1 (e.g 0 = 1 Tab page, 3 = 4 Tab Pages). Can anyone help me with the VB code which I can run when I open the from.
Thanks.
 
Simple Software Solutions

On the asumption you have a record that has 10, so all 10 tab pages are visible, is there something each of the tabbed pages?

First you need to give each page a meaningful name

Then on the selection of record you will determine how many pages to show

If n = 9 then
Me.PageName.Visible = False
End If

But what jumps out a me is ok the current record says 5, which 5 pages do I make invisble? what is the logic for this?

CodeMaster::cool:
 
Hi DCrake,
Thanks for your reply. Let me try and explain the functionality of the form. The user will be able to enter data in a subform (continues) which I put on the main form on top of the tab control. So just one sub form. Depending on the value of the record (1 to 10) I want to show an equal number of tab pages in the Tab control. I use the Tab pages for filtering the data in the Sub Form.
So I need some smart code which is executed when the form opens and shows the number of Tab pages equal to the number in the record.
It would be great if there was a way to give the tab pages a name in the same code. Idealy first tab would be called general, second: unit #1 etc.
Appreciate your reply.
 
ok- i have something similar to this -
Productname is a drop down box with various products numbered
so product 3 then the following tabs are invisible All risks and Cancellation

remember you will also need this code on your main form as well so when you open it it looks at tthe product number and does the same filtering

hope this helps

Productname = Combo26.Column(1)
If Me.Product = 3 Then
Me.All_Risks.Visible = False
Me.Cancellation_Sum.Visible = False
Else
Me.All_Risks.Visible = True
Me.Cancellation_Sum.Visible = True
Me.Refresh
If Me.Product = 2 Then
Me.All_Risks.Visible = False
Me.Cancellation_Sum.Visible = False
Else
Me.All_Risks.Visible = True
Me.Cancellation_Sum.Visible = True
Me.Refresh

If Me.Product = 6 Then
Me.Legal_Liability.Visible = False
Me.All_Risks.Visible = False
Me.Cancellation_Sum.Visible = True
 
Simple Software Solutions

It would be great if there was a way to give the tab pages a name in the same code. Idealy first tab would be called general, second: unit #1 etc.
Appreciate your reply.

My earlier post stated that you can give individual pages on a tab control a name, this could be the same name as the tab page caption.

The control itself has a name

TabCtrl01
Page1
Page2
Page3
etc

These names can be addressed independantly as you would with any control.

CodeMaster:
 
Yes it does help.
Now all I need to do is come up with a smart While n > statement or something to hide all tabs which the user should not see.
Cheers.
 
Simple Software Solutions

If you was to write it down in psuedo code (plain english) what would it look like?

Using an actual example helps to convert it to actual code.
 
ok here goes:

when the form opens:
the value for number of tabs from the table = e.g. 4 which means I have to hide tab 5 to 10.
The name of the tabs are: tab1(index 0) = General, tab2(index 1) = Unit_1 tab3(index 2) = Unit_2 etc.
I have been experimenting with Do While with a counter starting at inthis case 4 and Loop until 10. However it is difficult to use the counter for the number behind the name e.g. counter = 6 for Unit_6
I will try using the Select Case now.
Thanks
 
The case statement works. Probably not the best way to solve this but, well, not bad for an amature...

Private Sub Form_Open(Cancel As Integer)

Select Case NumberOfUnits
Case 0
Me.Unit_1.Visible = False
Me.Unit_2.Visible = False
Me.UNIT_3.Visible = False
Me.UNIT_4.Visible = False
Me.UNIT_5.Visible = False
Me.UNIT_6.Visible = False
Me.UNIT_7.Visible = False
Me.UNIT_8.Visible = False
Me.UNIT_9.Visible = False
Me.UNIT_10.Visible = False
Case 1
Me.Unit_2.Visible = False
Me.UNIT_3.Visible = False
Me.UNIT_4.Visible = False
Me.UNIT_5.Visible = False
Me.UNIT_6.Visible = False
Me.UNIT_7.Visible = False
Me.UNIT_8.Visible = False
Me.UNIT_9.Visible = False
Me.UNIT_10.Visible = False
Case 2
Me.UNIT_3.Visible = False
Me.UNIT_4.Visible = False
Me.UNIT_5.Visible = False
Me.UNIT_6.Visible = False
Me.UNIT_7.Visible = False
Me.UNIT_8.Visible = False
Me.UNIT_9.Visible = False
Me.UNIT_10.Visible = False
Etc.
End Select
 

Users who are viewing this thread

Back
Top Bottom