Link to home
Start Free TrialLog in
Avatar of Ralph Gould
Ralph GouldFlag for United States of America

asked on

ms access vba split-screen form needs to be refreshed on load

ms access 2010 vba have a split-screen form that needs the driving table link to be updated before updating. this is being done in the on-load event and then re-queried. When done the form is closed. The problem is the form does not have the current data for the selected item. If I run the open twice the data is correct on the second attempt. Currently in the on-load event I re-link and then requery the form. this doesn't seem to work until I do it twice. I have tried various combinations of requery, refresh and repaint, none of which seems to help.
Any help greatly appreciated.
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

if this form you mentioned above is the first form that open when you open the db,

create a start up form and do the updating of the driving table in the load event, close the start up form and open the split form.
Open event occurs first. Here you make sure all bits and pieces are there for the form to load. After that  current event triggers for each record.

Upload a sample database. Explain the problem starting from starting the database, to see the issue.
SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America 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 Ralph Gould

ASKER

its a split screen not subform. it is opened from a button on another form into a new window. all data prep is done in on-load event. does on open occur first?
ASKER CERTIFIED SOLUTION
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
No points please.

As hnasr said, OnOpen occurs first and this occurs before any data is loaded.

OnLoad fires when the forms recordset has been loaded, but before the first record has been displayed.  All controls are created at this point and the form is "ready to go".

So moving the code to OnOpen will help and will be the most efficient.    But with that said, if you requery in the OnLoad after taking care of the forms recordset and/or filtering, that should have worked as well (your doing extra work however).

Couple other things to be aware of:

1. You can cancel a form opening by setting Cancel = True in the OnOpen event if you need to, just be aware that the calling code will get a error 2501 raised.  

2. You can't stop a form from loading once past OnOpen (OnLoad for example cannot be canceled).

3. When the OnOpen fires, controls may or may not exist during the event.   If you need to reference a control in the OnOpen event, issue a Me.Repaint first.   This forces Access to instantiate all the controls before continuing.

HTH,
Jim.
Thank you all folks