Tab Control

  • Thread starter Thread starter Gary Hull
  • Start date Start date
You can put a subform on a tab page, and then have a tab control in that
subform. This is the closest to "nesting" that you can do.
 
You can put a sub-form on a tab page, and then have a tab control in that
sub-form. This is the closest to "nesting" that you can do.


Ken

Thanks for your suggestion

Is there a better way approach the problem?

I have some sub-forms on tabs on my form

I would like to access them from one form, but when I use the tab control
to hold the sub-forms

I have 15 tabs on the form. It gets to be a bit much

Thanks again
 
the way i approach it is: you can only look at one tab page of a tabcontrol
at a time, no matter how many tab pages you have. so you can only look at
the subform(s) contained on a single tab page at any given time. combine
this with the fact the the more bound subforms you put on a mainform, the
longer it takes to load the mainform - 15 bound subforms is a fairly
horrifying number. (i use three subforms on a single mainform only when i
absolutely must, two fairly often for related subdata, but preferably just
one whenever possible.)

try starting with one subform. you can put a tab control "on top" of it, and
the subform will "show through" every page. then add code to the tab
control's Change event procedure, to change the subform's SourceObject
property - and if necessary the LinkChildFields and LinkMasterFields
properties - to display the appropriate subform for the tab selected.

some variations:
1) i often use option group controls, with toggle buttons, at the top of a
subform control that has the Style property set to None so no tabs show. i
like having more control over the page "headers" than i can get using the
built-in tabs.

2) for many subforms, such as you have, i usually dispense with the tab page
"headers" altogether, and often the tab page itself. instead, i use a
listbox (bound to a table) that lists all the subforms i want to make
available to the user, with a visible column showing user-appropriate names,
and a hidden column containing the "real" form names. then i run code from
the listbox's AfterUpdate event procedure that changes the subform
SourceObject to the form name selected by the user in the listbox. i'm
currently using a this setup in a database at work, with a list of 34
available subforms at last count.

one of the great things about Access is the almost limitless ways you can
set up a user interface to achieve whatever your goal is.

hth
 
1) here's the code on an Option Group control (named grpTabs) that changes
the page on a TabControl (named TabCtl24):

Private Sub grpTabs_Click()

Me!TabCtl24 = Me!grpTabs
' isSetGrpTabs

End Sub

the trick is to set the OptionValue property of each toggle button, in the
option group, to the corresponding index value of the tab control page you
want to see. in other words, your first tab page's index is 0, the second
page is 1, the third page is 2, etc. choose the toggle button you want to
click to go to the first tab page, and set the button's OptionValue property
to 0, choose the button for the second page and set the button's OptionValue
to 1, etc. the value of a tab control is the value of the Index property of
the "current" page. so when you click on the toggle button with OptionValue
1, the code above sets the value of the tab control to 1, and the tab page
with that Index value gets the focus. it's really just that simple.

the second line of code, which i commented out, calls a separate procedure
to control the color of the text on each toggle button, according to which
one was selected (that's the "greater control vs using the built-in tabs"
that i was talking about in the earlier post). that procedure is not needed;
the single line of code is all you need to move from tab page to tab page.

2) the following is the RowSource for a listbox on a mainform, as

SELECT rptName, rptTitle, FROM tbl00SubformReports ORDER BY rptSortOrder;

i keep the list of available subforms in tbl00SubformReports, with the form
name in field rptName and the "user friendly" name in field rptTitle, and
field rptSortOrder used to control the order of records shown in the
listbox.

in the mainform, the listbox is called lstTable. the BoundColumn is 1, and
the ColumnWidths are 0";1.5". so the listbox value = the rptName of the
selected record in the listbox, while what the user sees is the rptTitle of
the selected record.

the name of the subform control, in the mainform, is ChildTable.

Private Sub lstTable_AfterUpdate()

If Not Me!lstTable = "" Then
Me!ChildTable.SourceObject = Me!lstTable
End If

Me!ChildTable.SetFocus
Me!lstTable.SetFocus

End Sub

the reason i check for a zero-length string in the listbox is because i have
records in tbl00SubformReports with no value in the rptName and rptTitle
fields. so in the listbox those records show up as "blank lines". i use them
to separate my 34 subform records into groups, via the rptSortOrder field,
just to make it easier for the user to find what s/he wants.

this code is obviously simple. the subform is not linked to the mainform, so
there are no LinkChildFields and LinkMasterFields properties to set. if
there were, i would set them in the same code that sets the SourceObject
property.

hth
 
Brilliant! Thanks Tina!

tina said:
the way i approach it is: you can only look at one tab page of a tabcontrol
at a time, no matter how many tab pages you have. so you can only look at
the subform(s) contained on a single tab page at any given time. combine
this with the fact the the more bound subforms you put on a mainform, the
longer it takes to load the mainform - 15 bound subforms is a fairly
horrifying number. (i use three subforms on a single mainform only when i
absolutely must, two fairly often for related subdata, but preferably just
one whenever possible.)

try starting with one subform. you can put a tab control "on top" of it, and
the subform will "show through" every page. then add code to the tab
control's Change event procedure, to change the subform's SourceObject
property - and if necessary the LinkChildFields and LinkMasterFields
properties - to display the appropriate subform for the tab selected.

some variations:
1) i often use option group controls, with toggle buttons, at the top of a
subform control that has the Style property set to None so no tabs show. i
like having more control over the page "headers" than i can get using the
built-in tabs.

2) for many subforms, such as you have, i usually dispense with the tab page
"headers" altogether, and often the tab page itself. instead, i use a
listbox (bound to a table) that lists all the subforms i want to make
available to the user, with a visible column showing user-appropriate names,
and a hidden column containing the "real" form names. then i run code from
the listbox's AfterUpdate event procedure that changes the subform
SourceObject to the form name selected by the user in the listbox. i'm
currently using a this setup in a database at work, with a list of 34
available subforms at last count.

one of the great things about Access is the almost limitless ways you can
set up a user interface to achieve whatever your goal is.

hth
 

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

Back
Top