By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

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

100+
P: 176
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:
Expand|Select|Wrap|Line Numbers
  1. Forms!frmMain!sfrmForm1.Form.RecordSource = "RecordSource1"
  2. DoEvents
  3. Forms!frmMain!sfrmForm2.Form.RecordSource = "RecordSource2"
  4. DoEvents
  5.  
(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.
Oct 22 '08 #1
Share this Question
Share on Google+
8 Replies


FishVal
Expert 2.5K+
P: 2,653
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
Oct 22 '08 #2

100+
P: 176
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?
Oct 22 '08 #3

FishVal
Expert 2.5K+
P: 2,653
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?
Oct 22 '08 #4

100+
P: 176
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.
Oct 22 '08 #5

100+
P: 176
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?
Oct 22 '08 #6

missinglinq
Expert 2.5K+
P: 3,532
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)>
Oct 22 '08 #7

100+
P: 176
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!
Oct 23 '08 #8

NeoPa
Expert Mod 15k+
P: 31,186
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.
Oct 23 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.