Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Odd Behavior re: Form_Load event order

Status
Not open for further replies.

jv6886

Programmer
Dec 31, 2002
46
0
0
US
My company has an Access database in 2000 format. We're coming up with some errors when running on a machine with Access 2003 installed. The scenario in question is a form with a subform on it.

I discovered that, when stepping through the code on a machine with Access 2000 installed, the form's Form_Load event is fired before the subform's Form_Load event. On a machine with Access 2003 installed, it is the opposite... the subform's Form_Load event fires before the form's Form_Load event.

Anybody have any explanations for this (seemingly) odd behavior?

Thanks,
wcprog
 
In the vba-help file of Access 2003 (F1) I found the underneath text. To trigger the events in an other order (Access 2000?), I moved the focus from the mainform to the subform after the load_event of the mainform... Maybe it will help you.

Working with subforms
When you open a form containing a subform, the subform and its records are loaded before the main form. Thus, the events for the subform and its controls (such as Open, Current, Enter, and GotFocus) occur before the events for the form. The Activate event doesn't occur for subforms, however, so opening a main form triggers an Activate event only for the main form.

Similarly, when you close a form containing a subform, the subform and its records are unloaded after the form. The Deactivate event doesn't occur for subforms, so closing a main form triggers a Deactivate event only for the main form. The events for the controls, form, and subform occur in the following order:

Events for the subform's controls (such as Exit and LostFocus)
Events for the form's controls (including the subform control)
Events for the form (such as Deactivate and Close )
Events for the subform
Note Because the events for a subform occur after the main form is closed, certain events such as canceling the closing of the main form from an event in the subform, will not occur. You may need to move these types of validations to an event on the main form.


Opening and closing a form
When you open a form, the following sequence of events occurs for the form:

Open ? Load ? Resize ? Activate ? Current

If there are no active controls on the form, the GotFocus event also occurs for the form after the Activate event but before the Current event.

When you close a form, the following sequence of events occurs for the form:

Unload ? Deactivate ? Close

If there are no active controls on the form, the LostFocus event also occurs for the form after the Unload event but before the Deactivate event.

Pampers [afro]
Just let it go...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top