Niniel said:
This may be a silly question
Actually, it is one of the best questions here for the whole week!!!
Often, not much though is given to the on-open, vs that of on-load
On-open is generally for testing of criteria for the record to PREVENT the
form load.
So, for example, I have some custom record locking code. In all of my forms
(that need record locking), I use:
If IsNull(Me!ID) = False Then
If AskForLock("tour*" & Me!ID) = False Then
Cancel = True
End If
End If
So, my locking table is the table name + "*" + record id
If the lock is un-successful, then we cancel the form load.
So, you can prevent, or "cancel" the form load by setting cancel = true in
the on-open event.
It is VERY IMPORTANT to note that on-open CAN NOT MODIFY THE VALUES of those
bound controls, or fields in the table. IT IS TOO SOON.
Since you can cancel the on-open event, and you can NOT modify values in the
open event, then it follows that:
a) on-open = test code for particular record conditions to be met,
prevent load of form possible
b) on-load = code to setup variables, setup fields, setup visible,e
tc. I mean, why run all of this code if the form is going to be cancelled by
the on-open event?
so, there is a VERY nice division between which of the two events to use.
for code setup, variables setup, and general setup code for the form, it
obviously belongs in the on-load event.
code that will test, check, or prevent the form from loading belong in the
on-open event.
So, actually, this is TERRIFIC question on your part, and often user of
access don't distinguish the two events very much.
so, as general rule, the on-open event is for testing, and preventing the
form from loading
and, on-load is where you would put your setup and initialization code for
the form....
if any, is better suited to set parameters? I'm turning some tabs
invisible,
and am disabling the mouse scroll wheel. I later make the tabs visible via
command button.
I would use on-load for the above. However, one could argue that your code
DOES NOT modify, or change any data, so it *could* be placed in the on-open
event. There is no hard, and fast rule, but I generally *only* put code that
will *prevent* the form from loading in the on-open event (this means I
*always* know to look for setup code in the on-load).