Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

circular dependency between subforms, problem cased by subform loading order

38 views
Skip to first unread message

sas...@gmail.com

unread,
Sep 27, 2005, 3:06:35 PM9/27/05
to

I have a main form "topform" contaning "subform1" and "subform2"

The goal is:
I need to requery subform2 on CURRENT event of subform1, and I need to
load subform2 contents based on settings on subform1.

The problem is:
Order of loading is:
subform1
subform2
topform

When subform1 is loaded, CURRENT event happens, subform2 is not yet
loaded so my code to requery subform2 fails!

Questions:
1-What is a good strategy to handle such situations in general.
2-How do I handle this case specifically?
3-Is there a way to know if a subform is yet loaded or not?


Thanks.

jimfo...@compumarc.com

unread,
Sep 27, 2005, 5:02:33 PM9/27/05
to

Here's what I do:

'Code behind subform1

Private Sub Form_Current()
If Not IsNull(Me.IdIDO) Then
Call Form_frmIDOReconciliation.RequerySubform2(CStr(Me.IdIDO))
End If
End Sub

'Code behind the main form

Public Sub RequerySubform2(strIdIDO As String)
'Set visible = false and make visible to keep subform OnCurrent from
running
If SubformIDOReconciliation2.Visible = False Then
SubformIDOReconciliation2.Visible = True
Exit Sub
End If
SubformIDOReconciliation2.Form.RecordSource = "SELECT * FROM
tblIDOItems WHERE IdIDO = " & strIdIDO & " ORDER BY IdItem;"
SubformIDOReconciliation2.Form.Refresh
SubformIDOReconciliation2.Form.Repaint
End Sub

Starting the subform visible property false seems to keep its Current
event from running immediately after the form opens. I don't know what
will happen if the RecordSource is not set dynamically though. Perhaps
this will give you an idea. When an IDO is clicked on subform1's
datasheet the corresponding items show up in subform2's datasheet.
Subform2 doesn't show until an IDO line is clicked in subform1. I
really haven't thought much about the best strategy. I just used the
first idea that worked for me. I suppose this would be referred to as
'lazy optimization' or 'optimization on demand.' I also haven't
thought about how to determine if a subform is loaded or not. I assume
they get loaded when the form opens unless the SourceObject property of
the Subform control is used to load a different subform later.

James A. Fortune

0 new messages