Load Tab Data on Click

G

geetarista

I have a form with 6 different tabs that takes a very long time to
load. Is there a way that I can only have the main form and the first
tab load when the form opens and then only load the data for the other
tabs when they are clicked?
 
V

Van T. Dinh

I am guessing that you have a Subform in each of the Tab Pages of the
TabControl?

If that the case, you can leave the SourceObject Property of the other 5
Subforms bank and use the TabControl_Change Event to assign an appropriate
Form (name) to the SourceObject of the required Subform.

Another (more efficient way, I think) is to use only one Subform Control
sitting on top of the TabControl and not on a particular Tab Page and use
code to change the SourceObject as required. This may depend on the
LinkMasterFields / LinkChildFields combination required for your Subforms
....
 
G

geetarista

If I do use the TabControl_Change Event to assign the Source Object,
wouldn't I only be able to either change one or change them all? How
do I make it so that the data is loaded when I click on the tab page I
want?

Maybe I just don't completely understand... :)
 
V

Van T. Dinh

Which method do you want to go with? A Subform Control on each *TabPage* or
only ONE Subform Control on top of the TabControl, i.e. the SubformControl
is actually outside the TabControl and directly on the Form?
 
G

geetarista

Since we have many different buttons and even subforms on each tab, I
think it would work better to have different tab pages.
 
V

Van T. Dinh

In that case, you only need to use the TabControl_Change Event to see which
TabPage you are on, check whether the SourceObject has been set or not and
if it is not, assign the appropriate Form as the SourceObject. Assuming
that you set the SourceObject for the Subform on the first TabPage
(TabControl value = 0)only, then the code should be soomething like:

********
Private Sub tcLeft_Change()

On Error GoTo tcLeft_Change_Err
Application.Echo False, "Processing ..."
With Me
Select Case tcLeft
Case 0 ' First TabPage
' Do nothing. SourceObject loaded.

Case 1 ' Second TabPage
If .sfrOnSecondPage.SourceObject <> "TheFormToBeUsedAsTheSubform"
Then
.sfrOnSecondPage.SourceObject = "TheFormToBeUsedAsTheSubform"
End If

Case 2 ' Third TabPage
' Similar code
Case 3
' ...
Case 4
' ...
' ...
End With

tcLeft_Change_Exit:
On Error Resume Next
Application.Echo True
Exit Sub

tcLeft_Change_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description & vbCrLf &
vbCrLf & _
"(Programmer's note: Form_frmProduct_View.tcLeft_Change)", _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume tcLeft_Change_Exit
End Sub
********
 
G

geetarista

Thank you so much Van! That worked perfectly!!
In that case, you only need to use the TabControl_Change Event to see which
TabPage you are on, check whether the SourceObject has been set or not and
if it is not, assign the appropriate Form as the SourceObject. Assuming
that you set the SourceObject for the Subform on the first TabPage
(TabControl value = 0)only, then the code should be soomething like:

********
Private Sub tcLeft_Change()

On Error GoTo tcLeft_Change_Err
Application.Echo False, "Processing ..."
With Me
Select Case tcLeft
Case 0 ' First TabPage
' Do nothing. SourceObject loaded.

Case 1 ' Second TabPage
If .sfrOnSecondPage.SourceObject <> "TheFormToBeUsedAsTheSubform"
Then
.sfrOnSecondPage.SourceObject = "TheFormToBeUsedAsTheSubform"
End If

Case 2 ' Third TabPage
' Similar code
Case 3
' ...
Case 4
' ...
' ...
End With

tcLeft_Change_Exit:
On Error Resume Next
Application.Echo True
Exit Sub

tcLeft_Change_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description & vbCrLf &
vbCrLf & _
"(Programmer's note: Form_frmProduct_View.tcLeft_Change)", _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume tcLeft_Change_Exit
End Sub
********
 

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