|
With Events, it is important to remember that they occur in order and the
attachment of your code to a particular event will set when that code is run.
Sometimes it can be a bit of trial and error to determine where the best
position is to place your Macro or Code.
If you open a Form, the following Events occur in the following order:
Open
Load
Resize
Activate
(GotFocus)
Current
If there is no active Control on a Form, the GotFocus event will occur. If there is an Active Control, the GotFocus Event will not occur. This is because the Focus is on the form rather than a Control, and therefore this Event can occur. Open Form Events.
On Open Event
The Open Event occurs when a form is opened, but before the first record is displayed. Therefore, attach code here that you wish to run as soon as the form is opened. The Open event will not occur when you activate (move to a form) a form that's already open, i.e. if you open a second form from the first form, then close the second form, the first form’s On Open Event will not occur as the first form has not been closed and opened, it has just been hidden behind the second form.
If the Form is based on a Query, the Query is run prior to the On Open Event.
On Load Event
Whereas the on Open Event occurs when the form is opened and before the first record is displayed, the On Load Event occurs when the first record is displayed.
On Resize Event
The Resize Event occurs when a form is opened or whenever the form’s size changes.
On Activate Event
The Activate Event occurs when a form receives the focus and becomes the active window.
You make a form active by: Opening it; Clicking on form with your mouse, or clicking a control on the form; Invoking the SetFocus method. The On Activate event can only occur if the form is visible. If the form is not visible an error will occur.
On GotFocus Event this rarely used Event only occurs when the form gets focus, but only if there are no visible enabled controls on the form.
On Current Event
The On Current event occurs when the focus moves to a new or different record making it the current record, or when the Form is Refreshed or Requeried.
This Event occurs when a form is opened, whenever the focus leaves one record and moves to another, and when the Form’s underlying Table or Query is requeried. This event is one of the more commonly used Events. If you wish to run code whenever a record is displayed, this is the place to put it.
Do you like this tip? Subscribe to my Newsletter to receive tips
via email.
Click Here to subscribe.
|