By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Tab Control and Dynamic subForm Linking

P: n/a
I am using the following code in my TabControl to manage subform
loads. The code assigns the subForms SourceObject.

- Do I also need code to DeAssign the SourceObject when leaving the
Tab, I'm thinking the Table will stay open otherwise ???

- Do I also need to use code to Assign the Child&Master Links, or can
I just type the names into the subForms Control Property and just
depend on the SourceObject to link to Table???

- Do I need to toggle the subForms Visible property when entering and
leaving the tab??? I thought I read this somewhere?
Private Sub tabPersonnel_Change()
'************************************************* *****
' PageTab Management
Select Case Me.tabPersonnel.Value
Case Me.pgGeneral.PageIndex
'mainform
strSelection = "GENERAL"
Case Me.PgPersonal.PageIndex
'mainform
strSelection = "PERSONAL"
Case Me.PgPromotions.PageIndex
'subForm
strSelection = "PROMOTIONS"
Me.[subPROMO].Visible = True
Me.[subPROMO].SourceObject = "F-PROMO"
Case Me.pgCredentials.PageIndex
'subForm
strSelection = "CREDENTIALS"
Me.[subCRED].Visible = True
Me.[subCRED].SourceObject = "F-CRED"
Case Else
MsgBox "Dunno what to do with page "
End Select
End Sub

Thanks
Greg

Feb 24 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Why are you assigning the SourceObject like this? What's the purpose? Is it
to make the form load faster (because it doesn't have to load all subforms
at the start)? Is it to reduce memory usage?

Do you actually need multiple subforms loaded at once? It's a bit hard to
give advice without understanding what you want to achieve.

If you only need one subform loaded at a time, one approach is to place a
subform directly on the main form, i.e. not on any of the pages of the tab
control. In fact, the Height of the tab control will be just enough for the
tabs. Then for each Page in the tab control, set the page's Tag property to
the name of the form you want loaded into the subform control. You can then
load the correct subform by adding this line to the Change event of your tab
control:

Me.[Sub1].SourceObject = Me.[Tab1].Pages(Me.[Tab1].Value).Tag

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<Ap******@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
>I am using the following code in my TabControl to manage subform
loads. The code assigns the subForms SourceObject.

- Do I also need code to DeAssign the SourceObject when leaving the
Tab, I'm thinking the Table will stay open otherwise ???

- Do I also need to use code to Assign the Child&Master Links, or can
I just type the names into the subForms Control Property and just
depend on the SourceObject to link to Table???

- Do I need to toggle the subForms Visible property when entering and
leaving the tab??? I thought I read this somewhere?
Private Sub tabPersonnel_Change()
'************************************************* *****
' PageTab Management
Select Case Me.tabPersonnel.Value
Case Me.pgGeneral.PageIndex
'mainform
strSelection = "GENERAL"
Case Me.PgPersonal.PageIndex
'mainform
strSelection = "PERSONAL"
Case Me.PgPromotions.PageIndex
'subForm
strSelection = "PROMOTIONS"
Me.[subPROMO].Visible = True
Me.[subPROMO].SourceObject = "F-PROMO"
Case Me.pgCredentials.PageIndex
'subForm
strSelection = "CREDENTIALS"
Me.[subCRED].Visible = True
Me.[subCRED].SourceObject = "F-CRED"
Case Else
MsgBox "Dunno what to do with page "
End Select
End Sub

Thanks
Greg
Feb 24 '07 #2

P: n/a
Why are you assigning the SourceObject like this? What's the purpose? Is it
to make the form load faster (because it doesn't have to load all subforms
at the start)? Is it to reduce memory usage?
Do you actually need multiple subforms loaded at once?
I am attempting to make the form load faster and reduce memory usage.
I did not realize that this code is reading multiple subforms at once,
I thought it would load a subform only when the tab was selected. The
SourceObject is assigned in the change event of the TabControl when a
tab is selected?
If you only need one subform loaded at a time, one approach is to place a
subform directly on the main form, i.e. not on any of the pages of the tab
control.
I read that there were two approaches. The one you mention and the
approach that I was following. And it seems to work, but I am not
sure about the questions I previously asked about.
In fact, the Height of the tab control will be just enough for the
tabs. Then for each Page in the tab control, set the page's Tag property to
the name of the form you want loaded into the subform control. You can then
load the correct subform by adding this line to the Change event of your tab
control:
Me.[Sub1].SourceObject = Me.[Tab1].Pages(Me.[Tab1].Value).Tag
I really do not understand how I should place the subform on the main
form. I will eventually have up to 10-subforms. Do they need to be
fully sized or do I place them reduced in size on the main form? Do I
set their visibility off? How do they wind up showing on my Page and
sized properly? When the user selects a different tab, should the
SourceObject for the last subform be set to ""? Do I need to Assign
and DeAssign the Child/Parent in code, or just manually set the
subform property?

Sorry for so many questions, but am struggling to make this happen ;)

Thanks Allen

Greg
Feb 24 '07 #3

P: n/a
If the goal is to reduce loading time and memory usage, reusing a single
subform control would be the logical choice.

If you put the subform control on the form before adding the tab control, it
is sitting directly on the form. You can also do it by selecting the subform
control in the Toolbox, and clicking outside the tab control (i.e. on the
form itself.)

Hopefully you understand the difference between a subform control (the
rectangle on your form where you load a subform), and a subform (the form
that gets loaded into the subform control, typically specified in the
SourceObject property of the subform control.)

Since there is only one subform control, and you load different forms into
it (depending on which tab the user clicked on), there is no need to set the
Visible property. Loading a new form into the subform control effectively
unloads the one that was there before.

For starters, you can place the subform control beside the tab control, type
the name of a form in to the Tag property of each Page of the tab control,
and then use that one line in the Change event of the tab control.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<Ap******@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
>Why are you assigning the SourceObject like this? What's the purpose? Is
it
to make the form load faster (because it doesn't have to load all
subforms
at the start)? Is it to reduce memory usage?
Do you actually need multiple subforms loaded at once?

I am attempting to make the form load faster and reduce memory usage.
I did not realize that this code is reading multiple subforms at once,
I thought it would load a subform only when the tab was selected. The
SourceObject is assigned in the change event of the TabControl when a
tab is selected?
>If you only need one subform loaded at a time, one approach is to place a
subform directly on the main form, i.e. not on any of the pages of the
tab
control.

I read that there were two approaches. The one you mention and the
approach that I was following. And it seems to work, but I am not
sure about the questions I previously asked about.
>In fact, the Height of the tab control will be just enough for the
tabs. Then for each Page in the tab control, set the page's Tag property
to
the name of the form you want loaded into the subform control. You can
then
load the correct subform by adding this line to the Change event of your
tab
control:
Me.[Sub1].SourceObject = Me.[Tab1].Pages(Me.[Tab1].Value).Tag

I really do not understand how I should place the subform on the main
form. I will eventually have up to 10-subforms. Do they need to be
fully sized or do I place them reduced in size on the main form? Do I
set their visibility off? How do they wind up showing on my Page and
sized properly? When the user selects a different tab, should the
SourceObject for the last subform be set to ""? Do I need to Assign
and DeAssign the Child/Parent in code, or just manually set the
subform property?

Sorry for so many questions, but am struggling to make this happen ;)

Thanks Allen

Greg
Feb 24 '07 #4

P: n/a
If you put the subform control on the form before adding the tab control, it
is sitting directly on the form. You can also do it by selecting the subform
control in the Toolbox, and clicking outside the tab control (i.e. on the
form itself.)
Hate making excuses, but I can't seem to manipuate the control
(SendToBack) in such a way that it sits Totally behind the
TabControl. The problem is my first 2-Tabs DoNot use subForms, they
display txtBoxes of the MainForm. The new subForm Control that was
sent to the background keeps covering over this.
Also, I was Previously varying the size of the subForm Control on each
TabPage to suit my display requirement. I believe I lose that using
the single subForm control.
The concept is excellent, but unfortunately I'm too far into my app to
turn back time wise, but want to use this from the getgo on my next
venture.

If Your Inclined, I would really like to continue along the path I was
on (ie unique subForm control on each page, and assign the
SourceObject when selecting the Tab.
I'm too far into my app to turn back time wise.

I really appreciate all your advice :)

Would I need code to DeAssign the SourceObject when leaving the
Tab, I'm thinking the Table will stay open otherwise ???

Do I also need to use code to Assign the Child&Master Links, or can
I just type the names into the subForms Control Property and just
depend on the SourceObject to link to Table???

Do I need to toggle the subForms Visible property when entering and
leaving the tab??? I thought I read this somewhere?

Thanks Again Allen
Greg

Feb 24 '07 #5

P: n/a
Ap******@gmail.com wrote:
I am using the following code in my TabControl to manage subform
loads. The code assigns the subForms SourceObject.

- Do I also need code to DeAssign the SourceObject when leaving the
Tab, I'm thinking the Table will stay open otherwise ???

- Do I also need to use code to Assign the Child&Master Links, or can
I just type the names into the subForms Control Property and just
depend on the SourceObject to link to Table???

- Do I need to toggle the subForms Visible property when entering and
leaving the tab??? I thought I read this somewhere?
Private Sub tabPersonnel_Change()
'************************************************* *****
' PageTab Management
Select Case Me.tabPersonnel.Value
Case Me.pgGeneral.PageIndex
'mainform
strSelection = "GENERAL"
Case Me.PgPersonal.PageIndex
'mainform
strSelection = "PERSONAL"
Case Me.PgPromotions.PageIndex
'subForm
strSelection = "PROMOTIONS"
Me.[subPROMO].Visible = True
Me.[subPROMO].SourceObject = "F-PROMO"
Case Me.pgCredentials.PageIndex
'subForm
strSelection = "CREDENTIALS"
Me.[subCRED].Visible = True
Me.[subCRED].SourceObject = "F-CRED"
Case Else
MsgBox "Dunno what to do with page "
End Select
End Sub

Thanks
Greg
Not sure if this will help in anyway. I shy away from tab forms as
they, for the most part, are a pita.

If you have a recordsource
Select custname, address, csz from table order by custname
you can't have a blank recordsource for the form unless you want to get
a bunch of #Name? indicators. But you could probably do
Select "" As CustName, "" As Address, "" As CSZ From Table
as the initial recordsource to create/pull up a blank record.

Another thing. Drop all of your subforms onto a form. Make all of
their visible properties false but the initial one. Then make some
buttons to simulate tabs. When you hit one, set all visible to false
but the one you want to make visible.

Feb 24 '07 #6

P: n/a
Okay, if your first 2 tabs do not use a subform, then the single generic
subform approach will not be suitable for this form (unless you can create
subforms for those 2 pages, which probably isn't your preferred design.)
Using different sized subforms is also an issue.

So, back to your original approach, with different subform controls on
different pages of the tab control. You can save the form with the
SourceObject property of the subforms left blank, and then assign the
property in the Change event of the subform if it has no already been
assigned:
With Me.[sbuPROMO]
If .SourceObject = vbNullString Then
.SourceObject = "F-PROMO"
End If
End With
and so on.

To answer your questions:
a) I would not deassign the SourceObject. Although it would save some
memory, you've already got the thing loaded, and the user is likely to come
back to the page.

b) When you assign the SourceObject, Access will have a guess at what you
need for LinkMasterFields/LinkChildFields. Just as at design time, it may
get it right (and if so it will probably be consistent) or it may not (in
which case you will need to assign the correct fields.)

c) There is no advantage in toggling the Visible property of the subform. It
doesn't show up anyway unless you are on that page, so it serves no purpose
to show/hide it.

HTH.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<Ap******@gmail.comwrote in message
news:11**********************@s48g2000cws.googlegr oups.com...
>If you put the subform control on the form before adding the tab control,
it
is sitting directly on the form. You can also do it by selecting the
subform
control in the Toolbox, and clicking outside the tab control (i.e. on the
form itself.)

Hate making excuses, but I can't seem to manipuate the control
(SendToBack) in such a way that it sits Totally behind the
TabControl. The problem is my first 2-Tabs DoNot use subForms, they
display txtBoxes of the MainForm. The new subForm Control that was
sent to the background keeps covering over this.
Also, I was Previously varying the size of the subForm Control on each
TabPage to suit my display requirement. I believe I lose that using
the single subForm control.
The concept is excellent, but unfortunately I'm too far into my app to
turn back time wise, but want to use this from the getgo on my next
venture.

If Your Inclined, I would really like to continue along the path I was
on (ie unique subForm control on each page, and assign the
SourceObject when selecting the Tab.
I'm too far into my app to turn back time wise.

I really appreciate all your advice :)

Would I need code to DeAssign the SourceObject when leaving the
Tab, I'm thinking the Table will stay open otherwise ???

Do I also need to use code to Assign the Child&Master Links, or can
I just type the names into the subForms Control Property and just
depend on the SourceObject to link to Table???

Do I need to toggle the subForms Visible property when entering and
leaving the tab??? I thought I read this somewhere?

Thanks Again Allen
Greg


Feb 25 '07 #7

P: n/a
Thanks for the advice Allen.
Makes sense in the scope of my app.

Greg

Feb 25 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.