Form_Open VS. Form_Load

  • Thread starter Thread starter Norbert
  • Start date Start date
N

Norbert

Please can someone explain:

What is the difference between
the form property:
Form_Open and Form_Load??

advantage/disadvantage of one over the other.

thanks!
Norbert
 
Open fires first.
The form is not visible at this time.
You can cancel this event if you don't want to the form to open.
If you want to change the RecordSource or set a Filter or OrderBy property,
it makes sense to do it at this stage before the data has been retrieved. If
you need to set the DefaultValue for controls, use the Open event.

Load occurs when the data has fetched (at least the first record). Use this
event if you need to read/respond to the data. You cannot cancel this
event.

That's the basic idea of the events. Access is actually a bit more flexible
than that, e.g. you can read Me.RecordsetClone.RecordCount in the Open event
(even though the data has not theoretically been fetched) so you can cancel
the opening of the form if there are no records.
 
The on open event is good for testing things like no records, and shutting
down the form. The on-open event has a "cancel" option where as the on-load
does not.

Hence, the general purpose of the on-open event is to test that certain
condition are met BEFORE the form actually loads. If you do a cancel in the
on-open, then the form does not load, and the code in the on-load event DOES
NOT run.

I use the on-open to check for record locking and allow the user to "bail
out" if another user is editing the data for example.

Further, values of the fields etc CAN NOT be changed in the on open. So, you
can't use on-open to setup values in controls.

so, we get:

on-open
Allows you to cancel the form load, and it is too soon to modify field
values on the form.

on-load
This is where you can set-up field defaults. Set-up some code variables
and code stuff that you need to run when the form loads. You can modify the
value of fields at this point. So, you basic start-up and setup code should
go in the on-load, since on-open is too soon to modify values.

So, you get a very nice natural division between the on-open code (test and
verify stuff), and the on-load (set-up and initialise stuff).
 
Back
Top