Increasing speed - load subforms on tabs only when tab clicked?

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

Hi,

I created a tabbed form, with subforms on a number of the tabs. I was
surprised to find that the subforms and their data loads when the form is
first loaded. I suspect that this could slow things down once my database
gets more data.

The database will be split into data.mdb on the server and forms.mdb on each
local desktop.

Should I allow the subform to load but simply not assign the recordsource
until the tab is clicked? (I know how to change recordsource at runtime)

Or should the tab be empty untill the tab is clicked, and then the subform
loaded? (unsure how to do this one)

What even should I use to trigger the above? I found that
TabControl_OnChange works, but how do I tell which tab was selected?

( Page1_click event only occurs when the body of the page is clicked, not
just the "pageone" tab' yet TabControl_click does nothing ever that I could
see.)


Thanks

Brian
 
Hi Brian,

Multiple subforms will slow down a form. The way to get around this is to
use *unbound* subform controls on each of the tab pages except the first one
(ie clear the SourceObject property on each). Then create an OnChange event
for the tabcontrol itself that sets the SourceObject property of correct
subform based on the new value of the tabcontrol. Remember that the value of
the tab control is actually the page index of the current tab page where 0
refers to the first tab page.

When I design a complex for this way, my onChange event also clears the
SourceObject of the subform that is being hidden. Here's some sample code -
note that on each of the cases instead of using absolute page numbers I get
the page number by getting the pageindex of a named page. I do this because
the page index of a page changes if you reorder the pages but I tend to
leave the names alone once I've set them. This just reduces maintenance and
prevents weird errors when you reorder the pages but forget to adjust the
code.

'Module level variable
Private mIntCurTabPage As Integer

Private Sub TabCtl8_Change()
'Clear the SourceObject of subform on tabpage we're leaving
Select Case mIntCurTabPage
Case Me.TabCtl8.Pages("pgFirstPageName").PageIndex
Me.sfrmFirst.SourceObject = vbNullString
Case Me.TabCtl8.Pages("pgSecondPageName").PageIndex
Me.sfrmSecond.SourceObject = vbNullString
Case Me.TabCtl8.Pages("pgThirdPageName").PageIndex
Me.sfrmThird.SourceObject = vbNullString
Case Me.TabCtl8.Pages("pgFourthPageName").PageIndex
Me.sfrmFourth.SourceObject = vbNullString
End Select

Select Case Me.TabCtl8
Case Me.TabCtl8.Pages("pgFirstPageName").PageIndex
Me.sfrmFirst.SourceObject = "sfrmOrders"
Case Me.TabCtl8.Pages("pgSecondPageName").PageIndex
Me.sfrmSecond.SourceObject = "sfrmOrders2"
Case Me.TabCtl8.Pages("pgThirdPageName").PageIndex
Me.sfrmThird.SourceObject = "sfrmOrders3"
Case Me.TabCtl8.Pages("pgFourthPageName").PageIndex
Me.sfrmFourth.SourceObject = "sfrmOrders4"
End Select
mIntCurTabPage = Me.TabCtl8
End Sub
 
Glad to hear it :-)

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Thank-you Sandra,
That worked like a charm - saved me a lot of time.

Brian

Sandra Daigle said:
Hi Brian,

Multiple subforms will slow down a form. The way to get around this
is to use *unbound* subform controls on each of the tab pages except
the first one (ie clear the SourceObject property on each). [snip]
 
Back
Top