Delay loading of subforms in tabs

G

gandhawk

I understand there is a way to delay loading of subforms
in tabs until the tab is clicked on resulting in the main
form loading quicker. Below is an exerp from the article
but I do not understand what the code should read.
1 - surpress the loading of the subform when main form is
loaded
2 - To loads the subform when the tab is clicked

The actual text in the article to reduce form loading time
is
"Watch out for Tab controls with many pages and subforms
on each page. Loading all those subforms will slow the
opening of your form. One alternative is to load the
subforms on a Tab control page only when that page is
selected. You can do this by using the Change event of the
Tab control to check the Value of the control. This tells
you the PageIndex of the selected page. You can set the
SourceControl property of your subforms only when the page
they appear on is selected; you can't set it in design
view."

Thanks

Jim
 
J

John Vinson

1 - surpress the loading of the subform when main form is
loaded
2 - To loads the subform when the tab is clicked

Save the Form with all the subforms *EMPTY* - i.e. the subform
controls should exist but should have no form in them, the
SourceObject should be blank.

In the Change event of the Tab Control, put code to set the
SourceObject property of the appropriate subform control to a text
string, the name of the Form.
 
J

John Vinson

I am having trouble with the code. Do you have an example?

Well, here's one off the top of my head:

Private Sub tbMainTab_Change()
Select Case tbMainTab.Value ' what page are you on?
Case 1
Me!subPage1Subform.SourceObject = "frmSubformForPage1"
Case 2
Me!subPage2Subform.SourceObject = "frmSubformForPage2"
<etc>

You'll need to also set the SourceObject of each subform to NULL in
each subform's LostFocus event, or some other suitable event.
 

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

Top