circular dependency between subforms, problem cased by subform loading order

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sasan3@gmail.com

    circular dependency between subforms, problem cased by subform loading order



    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.

  • jimfortune@compumarc.com

    #2
    Re: circular dependency between subforms, problem cased by subform loading order

    sasan3@gmail.co m wrote:[color=blue]
    > 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.[/color]

    Here's what I do:

    'Code behind subform1

    Private Sub Form_Current()
    If Not IsNull(Me.IdIDO ) Then
    Call Form_frmIDOReco nciliation.Requ erySubform2(CSt r(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 SubformIDORecon ciliation2.Visi ble = False Then
    SubformIDORecon ciliation2.Visi ble = True
    Exit Sub
    End If
    SubformIDORecon ciliation2.Form .RecordSource = "SELECT * FROM
    tblIDOItems WHERE IdIDO = " & strIdIDO & " ORDER BY IdItem;"
    SubformIDORecon ciliation2.Form .Refresh
    SubformIDORecon ciliation2.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

    Comment

    Working...