OnLoad event not firing (1 Viewer)

SyntaxSocialist

Registered User.
Local time
Today, 10:30
Joined
Apr 18, 2013
Messages
109
The RecordSource is a query and that query has criteria that refers to the hidden field.

Maybe it's the fact that I didn't sleep last night, but I'm still not able to get this working properly.

I've commented out the public sub that was being called from the general module, as well as the code in the subform's Current event that did the calling.

I set the main form's Record Source to
Code:
SELECT * FROM tblMain WHERE (([tblMain]![RecordID]=[Forms]![frmMain]![txtSubFrmRcrdID]));

My subform's Current event reads
Code:
    Me.Parent.txtSubFrmRcrdID = Me.RecordID
    Me.Parent.Requery

And I've moved the main form Open events back to the Load event.

What I'm ending up with, though, is the exact same problem: Load still doesn't fire. The culprit is Me.Parent.Requery in the subform Current Event. The requery calls the main form Current event, and the main form Current event calls 2 additional subs: One counts the total records displayed in a RecordsetClone of the main form and displays a count (e.g.: Record 3/786) near the bound controls. The other just enables/disables a set of buttons according to the position of the current record.

So here we are again :(
 

IronSasquatch

New member
Local time
Today, 10:30
Joined
Apr 9, 2014
Messages
9
I realize posting in a thread this old probably isn't the greatest thing to do, but I pinpointed the exact reason for this problem (as I had been having it myself and couldn't figure out why for some months). Pat definitely touched on the issue, namely the order in which the form events fire.

The issue stems from an event in any subform, not just firing before the parent's form load, but from that subform's event referencing the parent form or one of its controls. For example, I had a subform on a main menu that set a property of a control on its parent. Since the subform Form_Load event fires before the parent's, any code that modifies the parent will cause events on the parent form to fire before its own Form_Load. For some reason, this causes the Parent form to wait for focus to be returned to it before continuing with its own code execution, hence why clicking a button or closing the form causes the Form_Load event to finally fire.

To fix this, you'll have to find some way to do what you need to in the subform without referencing the parent in its Form_Load event. I hope this helps anyone else with this problem.
 
Last edited:

JBaumKC

New member
Local time
Today, 09:30
Joined
Jan 29, 2020
Messages
1
This is an old post but I though I would share my knowledge as I have faced this same issue. Depending on the actions you are taking in the events of the main form will cause the order of events to "reorder" or skip to the "onCurrent" event. Which if you have a tab control on your form none of the "initialization events" will occur. I have several forms in which contain a tab control, on the tab I have a blank form that has 1 line of code in the "GotFocus" event. In order for this event to fire and be unrestricted to the actions I can take in the main form's events. I use 1 line of code at the end of the main forms events.

In the main form the preferred method is to use the Open event. If in the open event you are calling out a field to set a value the Load event will not fire and it will skip all other events moving to the OnCurrent event. Most actions can be take in the Open event. So after the Open event has done what it needs to and just before the exit sub put this:

"Me.NameOfTabControl.Pages.Item("Name Of First Tab").SetFocus"

For example mine is this:

"Me.tabNotes.Pages.Item("Notes").SetFocus".

By doing this it will bring forward all of the underline forms in the tab controls, before they have an opportunity to be skipped by any action of the main form event actions.

Now in the blank form you set up on one of the tab controls go to it's event properties and use the "GotFocus" event put this line of code:

"DoCmd.BrowseTo acForm, "Name Of Form You Want Displayed", "", "", "", acFormEdit"

For example mine is this:

"DoCmd.BrowseTo acForm, "subfrm_Refund_List_Tab", "", "", "", acFormEdit"

In the main form depending on the choice you made to retrieve your record of the underline subfrm depends on if you need to add the values in the linked parent properties of the tab control. From a best practice and easy of management find a way not to use this feature. Get your available recordset of the underline form through other means. Myself I have SQL DB as a back end and get my recordsets via ADODB.

SideNote: if you are using Tabs in your main forms understanding the BrowseTo function is a worth while investment to understand. I have an Access DB with over 300 forms and all forms are opened from with in one form using a navigation window and the BrowseTo function. Keeps it clean and not overly excessive with popup's. This also allows for an option to stop using the Access interface and just complete your task via the form window.

Have Fun, let me know if you have any questions or would like to add any valuable input.

JB
 

Users who are viewing this thread

Top Bottom