Subform recordsource is query question

  • Thread starter Thread starter Ryan
  • Start date Start date
R

Ryan

I have a tabbed main form and a subform on one tab.
The subform recordsource is a query.
When I open the main form, the query for the subform runs
immediately.
Is this correct?
I thought it would only run when the tab was clicked.
 
That is correct. Often developers will unbind the subform by clearing the
SourceObject and then only setting it in code using the Change event of the
tab control just before the tab page comes into view. If the subform is
bound when the form opens then the subform's recordsource query runs.
 
When I use this approach it works fine, but before the tab page comes
into view a white surface is shown (it seems that this occurs during
the calculation of the SourceObjects data). How can I prevent this
from happening?????

I have tried this:

Private Sub TabCtl1_Change()
On Error GoTo ResetEcho
Application.Echo False
DoCmd.Hourglass True

ClearSubFormLinks ' ( clears SourceObjects for all tabs )
Select Case TabCtl1.Value
Case 0
frmTab0.SourceObject = "frmTab0"
Case 1
frmTab1.SourceObject = "frmTab1"
End Select

ResetEcho:
DoCmd.Hourglass False
Application.Echo True
On Error GoTo 0

End Sub

but this does not work ....

regards,

Peter

Sandra Daigle said:
That is correct. Often developers will unbind the subform by clearing the
SourceObject and then only setting it in code using the Change event of the
tab control just before the tab page comes into view. If the subform is
bound when the form opens then the subform's recordsource query runs.

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

I have a tabbed main form and a subform on one tab.
The subform recordsource is a query.
When I open the main form, the query for the subform runs
immediately.
Is this correct?
I thought it would only run when the tab was clicked.
 
I usually hide the subform while it is also detached from it's
SourceObject - then I set the visible property back to true *after* I set
the SourceObject -

So in your case, modify ClearSubFormLinks to also hide the subforms by
setting their visible property to false then your Select Case statement
would look like this (I've used With. . End With to shorten the references):

Select Case TabCtl1.Value
Case 0
with frmTab0
.SourceObject = "frmTab0"
.visible=true
end with
Case 1
with frmTab1
.SourceObject = "frmTab1"
.visible=true
end with
End Select


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


P said:
When I use this approach it works fine, but before the tab page comes
into view a white surface is shown (it seems that this occurs during
the calculation of the SourceObjects data). How can I prevent this
from happening?????

I have tried this:

Private Sub TabCtl1_Change()
On Error GoTo ResetEcho
Application.Echo False
DoCmd.Hourglass True

ClearSubFormLinks ' ( clears SourceObjects for all tabs )
Select Case TabCtl1.Value
Case 0
frmTab0.SourceObject = "frmTab0"
Case 1
frmTab1.SourceObject = "frmTab1"
End Select

ResetEcho:
DoCmd.Hourglass False
Application.Echo True
On Error GoTo 0

End Sub

but this does not work ....

regards,

Peter

Sandra Daigle said:
That is correct. Often developers will unbind the subform by
clearing the SourceObject and then only setting it in code using the
Change event of the tab control just before the tab page comes into
view. If the subform is bound when the form opens then the subform's
recordsource query runs.

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

I have a tabbed main form and a subform on one tab.
The subform recordsource is a query.
When I open the main form, the query for the subform runs
immediately.
Is this correct?
I thought it would only run when the tab was clicked.
 
thanks a lot for your reply Sandra,
It works, the flickering is gone, but now I sometimes get the message
that I cannot hide the control that has focus.

frmTab0.visible = false causes this error

How to prevent this?

Peter

Sandra Daigle said:
I usually hide the subform while it is also detached from it's
SourceObject - then I set the visible property back to true *after* I set
the SourceObject -

So in your case, modify ClearSubFormLinks to also hide the subforms by
setting their visible property to false then your Select Case statement
would look like this (I've used With. . End With to shorten the references):

Select Case TabCtl1.Value
Case 0
with frmTab0
.SourceObject = "frmTab0"
.visible=true
end with
Case 1
with frmTab1
.SourceObject = "frmTab1"
.visible=true
end with
End Select


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


P said:
When I use this approach it works fine, but before the tab page comes
into view a white surface is shown (it seems that this occurs during
the calculation of the SourceObjects data). How can I prevent this
from happening?????

I have tried this:

Private Sub TabCtl1_Change()
On Error GoTo ResetEcho
Application.Echo False
DoCmd.Hourglass True

ClearSubFormLinks ' ( clears SourceObjects for all tabs )
Select Case TabCtl1.Value
Case 0
frmTab0.SourceObject = "frmTab0"
Case 1
frmTab1.SourceObject = "frmTab1"
End Select

ResetEcho:
DoCmd.Hourglass False
Application.Echo True
On Error GoTo 0

End Sub

but this does not work ....

regards,

Peter

Sandra Daigle said:
That is correct. Often developers will unbind the subform by
clearing the SourceObject and then only setting it in code using the
Change event of the tab control just before the tab page comes into
view. If the subform is bound when the form opens then the subform's
recordsource query runs.

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


Ryan wrote:
I have a tabbed main form and a subform on one tab.
The subform recordsource is a query.
When I open the main form, the query for the subform runs
immediately.
Is this correct?
I thought it would only run when the tab was clicked.
 
This is one of those irritating issues that crops up now and again . . . one
way to solve it is to create a decoy textbox, set focus to it first then
change the visible property. If you size your decoy textbox .001 x .001 it
will be too small to be visible (even though the visible property is true)
but it can receive focus.

Another alternative is to setfocus elsewhere on your form - IOW you don't
have to create a decoy.

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


P said:
thanks a lot for your reply Sandra,
It works, the flickering is gone, but now I sometimes get the message
that I cannot hide the control that has focus.

frmTab0.visible = false causes this error

How to prevent this?

Peter

Sandra Daigle said:
I usually hide the subform while it is also detached from it's
SourceObject - then I set the visible property back to true *after*
I set the SourceObject -

So in your case, modify ClearSubFormLinks to also hide the subforms
by setting their visible property to false then your Select Case
statement would look like this (I've used With. . End With to
shorten the references):

Select Case TabCtl1.Value
Case 0
with frmTab0
.SourceObject = "frmTab0"
.visible=true
end with
Case 1
with frmTab1
.SourceObject = "frmTab1"
.visible=true
end with
End Select


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


P said:
When I use this approach it works fine, but before the tab page
comes into view a white surface is shown (it seems that this occurs
during the calculation of the SourceObjects data). How can I
prevent this from happening?????

I have tried this:

Private Sub TabCtl1_Change()
On Error GoTo ResetEcho
Application.Echo False
DoCmd.Hourglass True

ClearSubFormLinks ' ( clears SourceObjects for all tabs )
Select Case TabCtl1.Value
Case 0
frmTab0.SourceObject = "frmTab0"
Case 1
frmTab1.SourceObject = "frmTab1"
End Select

ResetEcho:
DoCmd.Hourglass False
Application.Echo True
On Error GoTo 0

End Sub

but this does not work ....

regards,

Peter

That is correct. Often developers will unbind the subform by
clearing the SourceObject and then only setting it in code using
the Change event of the tab control just before the tab page comes
into view. If the subform is bound when the form opens then the
subform's recordsource query runs.

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


Ryan wrote:
I have a tabbed main form and a subform on one tab.
The subform recordsource is a query.
When I open the main form, the query for the subform runs
immediately.
Is this correct?
I thought it would only run when the tab was clicked.
 
Back
Top