Can't reference control in subform

evanscamman

Registered User.
Local time
Yesterday, 23:58
Joined
Feb 25, 2007
Messages
274
I have a form with 2 subforms. Every time the OnCurrent event fires in subform 1 i want to change data in subform2.
After the form is loaded, this works fine - but during load, it appears that the 2nd subform is not available. I get the 'can't reference form/control error...

It seems that the OnCurrent event of the 1st subform fires before the 2nd subform has even loaded, thus it's controls cannot be referenced.
Is this true? If so, is there any way to determine the order that subforms load? Alphabetically? In order of creation?

Any input on this would be appreciated.

Thank you,
Evan
 
How are you referencing the subform? Is the 2nd subform within your 1st subform, or is it just parallel on the main form?
 
Subform problem solved

Bob - thx for the response. The subforms are parallel. I was referring to the 2nd subform from the 1st as: Parent!SubForm2.Form!Control

After mapping out the order of the Open,Load,and Current events of each subform, I have found that the events fire in this order:

Subform1_OnOpen
Subform1_OnLoad
Subform1_OnCurrent
Subform2_OnOpen
Subform2_OnLoad
Subform2_OnCurrent


I seems to me that Access should run OnOpen for each subform, then OnLoad, then OnCurrent. This would make more sense to me.

Regardless, referring to a control on Subform2 in the OnCurrent event of Subform1 produces an error because Subform2 has not loaded yet.

I also found that subforms are loaded in the order they were created.
(Tab Order, Alphabetical order, and physical placement of form did not have any effect.)
I deleted the 1st subform, and then recreated it - then the order was reversed. Subform2 loads 1st, then Subform1.
Not sure if this is a reliable fix or not, but it appears to be working well enough now.

Evan
 
Sounds like you have it in control, at least at the moment. Good work. I was at a Christmas gathering so I didn't get to check in until now.
 
The order you stated is correct because the model for forms in access is a linear processing model. The form painter triggers those events because with respect to a single session, form painter is single-threaded. Therefore, one can argue about the relative efficiency, but like it or not, the forms trigger as Open, Load, and Current because that is the form the single-threaded form painter is working on at the time.

To be honest, having parallel forms is relatively the rarer (less common) case anyway. To make the forms painter operate in a variant order from the order you described would only complicate the code and make Access bigger and buggier.
 
Hope I don't violate protocol by posting to an old thread, but I found you can change the order that subforms load in by using the 'Move to Front' or 'Move to Back' command in design mode.

Hope this may help someone.
Evan
 

Users who are viewing this thread

Back
Top Bottom