Link to home
Start Free TrialLog in
Avatar of Michael Paravicini
Michael ParaviciniFlag for Chile

asked on

Use of recordsource in main/subform causes Open Event in subform NOT to execute...

I use a mainform (Order) with a subform (order Details). However, I change the recordsource dynamically between table sets (order, orderitems) and (quote, quoteItems). This works fine as long as i stay within the same table set. As soon as I switch then from one set to the other, the subform will no longer execute (neither open nor the load event). I then have to reenter the load event in the subform to reestablish the event. Again, it will work perfectly but as soon as I change again to the other recordset I will experience the same problem (it makes no difference if i change from order to quotes or vice versa). Am really a bit desperate as I have no clue why it is behaving in this way. Any help is greatly appreciated!! Thanks Michael
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michael Paravicini

ASKER

Thank you so much Gustav - this has indeed resolved the issue. However, i now have a different problem. Whenever I switch between the table set the system gets confused with the new record pointers. Once I switch it will always edit the last record of the new table set rather than adding a new record. Even if I try to force with DoCmd ... gotoRecord acnewrecord etc it will still not create a new record. However, if i remain within the same table set - I have absolutely no problems.... Again, thank you so much !
It might be simpler to have two subforms - and hide the one not in use.
I take it that what you mean by "change the recordset dynamically between table sets" is that you have two different recordsources using different tables/queries and you are trying to juggle switching between the two sets of recordsources and getting the subform to properly synchronize with the main form.
It also sounds like you don't have a public procedure in your subform that you can call from your main (parent) form to initialize your subform whenever you change recordsets - that, apparently, is done in your subform's Open & Load events.

If you want your subform to run its Open and Load events after it is already open on the main form, you can simply set your main form's subform control's SourceObject to itself.  For example:
Me.MainformName.SubformControlName.SourceObject = Me.MainformName.SubformControlName.SourceObject

Or you can use the name of the subform:
Me.MainformName.SubformControlName.SourceObject  = "frmSubformName"
Either way, that will cause the subform to re-run it's Open and Load events.

Also, moving your Open & Load processes to a public procedure that you can call from the main form and from the open/load events can also work.
Not knowing exactly how you're changing your recordsources and getting your subform to try and synchronize makes it a little difficult to give you a perfect solution that will work in all cases.
Another thing to consider is that subform code runs before the main form code when the main form first opens.  Sometimes you can gain more control over what happens by leaving the subform's SourceObject blank at design time and setting it dynamically during the main form's code execution.

That little trick has solved a lot of subform control issues for me.
Thank you so much for this advice - it brought excellent results! Cheers Michael