We help IT Professionals succeed at work.

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

Michael Paravicini
on
51 Views
Last Modified: 2018-10-07
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
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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 !
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
It might be simpler to have two subforms - and hide the one not in use.
Mark EdwardsChief Technology Officer
CERTIFIED EXPERT

Commented:
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.
Mark EdwardsChief Technology Officer
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
Thank you so much for this advice - it brought excellent results! Cheers Michael
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.