Any way to determine the correct order of loading dependent subforms?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michael R
    New Member
    • Nov 2006
    • 176

    Any way to determine the correct order of loading dependent subforms?

    Hi everyone.

    I have a few subforms in the main form that are dependent on each other with their data (not with child/master fields). Sometimes I get an invalid reference error because the referenced subform isn't loaded (yet). To make them load in the correct order I need to delete them all, then insert them one by one in a correct order. If, later on, I decide to edit one of them of or send it to background, the order breaks and once again do I get the error.

    I've tried to determine the correct loading order with this code on the main form On Load event but to no avail:
    Code:
    Forms!frmMain!sfrmForm1.Form.RecordSource = "RecordSource1"
    DoEvents
    Forms!frmMain!sfrmForm2.Form.RecordSource = "RecordSource2"
    DoEvents
    (getting an error that the following action can't be done because it can't find the subform.)

    Does anyone know what can be done?
    Thanks a lot,
    Michael.
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello, Michael.

    Though I've not tested it thoroughly but it most like form components are loaded when Form_Load event fires (I guess you don't have subforms in main form being in datasheet view, this case subforms are being loaded on demand). Why not to move your code to the event handler?

    Regards,
    Fish

    Comment

    • Michael R
      New Member
      • Nov 2006
      • 176

      #3
      Originally posted by FishVal
      Hello, Michael.

      Though I've not tested it thoroughly but it most like form components are loaded when Form_Load event fires (I guess you don't have subforms in main form being in datasheet view, this case subforms are being loaded on demand). Why not to move your code to the event handler?

      Regards,
      Fish
      Most of my between-subforms code is event-oriented (for ex: changing a certain control in one from through AfterUpdate event changes records absolute position in another form from the On_Current event)

      What do you mean by moving the code to the event handler?

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        Originally posted by Michael R
        Most of my between-subforms code is event-oriented (for ex: changing a certain control in one from through AfterUpdate event changes records absolute position in another form from the On_Current event)

        What do you mean by moving the code to the event handler?
        I've assumed your code is run outside frmMain from module as soon as you reference it through Forms collection.
        So, when the code you've posted is invoked and where does it reside?

        Comment

        • Michael R
          New Member
          • Nov 2006
          • 176

          #5
          Originally posted by FishVal
          I've assumed your code is run outside frmMain from module as soon as you reference it through Forms collection.
          So, when the code you've posted is invoked and where does it reside?
          It is invoked from 1st subform's on current event using data (and variables) from 2nd subform.

          Comment

          • Michael R
            New Member
            • Nov 2006
            • 176

            #6
            Originally posted by Michael R
            It is invoked from 1st subform's on current event using data (and variables) from 2nd subform.
            Can I give any more details about this situation for the explanation to be clearer?

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              This is giving me a headache trying to follow, but there's one thing I think needs to be kept in mind, and it explains why the OPs original approach didn't work. In a form/subform setup, this is the order of event execution

              Subform Form_Open
              Subform Form_Load
              Main Form Form_Open
              Main Form Form_Load

              I think the RecordSource of the subforms need to be set to nothing until the Main form's Form_Load fires. At this point you can assign the RecordSource for each subform, in whatever order you need.

              Linq ;0)>

              Comment

              • Michael R
                New Member
                • Nov 2006
                • 176

                #8
                Originally posted by missinglinq
                I think the RecordSource of the subforms need to be set to nothing until the Main form's Form_Load fires. At this point you can assign the RecordSource for each subform, in whatever order you need.

                Linq ;0)>
                A good idea. I haven't tried it yet but I don't see why it should not work.
                Thanks!

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32645

                  #9
                  It also explains why your code in the original post didn't fix the problem. That code essentially runs AFTER the problem had already occurred. You have to stop the automatic attempt to load the recordsets. Designing them as without record sources (as Linq suggests) should resolve that for you.

                  Comment

                  Working...