Event Firing

  • Thread starter Thread starter Sheldon
  • Start date Start date
S

Sheldon

Which event(s) get fired and in which order when the
following buttons are clicked

1. The previous record button on a navigation control,
2. The next record record btton on a navigation control,
3. The create new record button on a navigation control,
4. The goto first record on a navigation control,
5. The goto last record on a navigation control,
5. The "X" control on the top of the form near the
min/max button.

Also can you determine in code which of the above was
clicked.

Thanks
 
Hi,

Depends on where you are, probably a control onExit/LostFocus, but
after, if the control is dirty, the beforeUpdate/afterUpdate of the control.
Then, the beforeUpdate/AfterUpdate, but those of the form, trying to save
the dirty record and finally, if the record save succeeded, the onCurrent
event of the form (first 5 cases) for the appropriate record. In the last
case, you would end up with form Unload then, if not cancelled, with its
Close event.


Hoping it may help,
Vanderghast, Access MVP
 
The order that the events fire is in the help file for the events. The name
of the topic is "Order of events for database objects" in Access 2003. I
believe earlier versions actually placed this in the help for each event. If
you want to test it, place a message box in each event (i.e. MsgBox "Form's
BeforeUpdate Event"). Each message box will pop-up as its event is run. Have
the text in the message box specify which event is running. The order that
the message boxes appear is the order in which the events fire.

Can you determine which click event caused things to run? Yes and no. If you
set a form level variable in the OnClick event of the control you could then
use the value of this variable to determine which control was clicked. If
the variable isn't set, then the form's built in buttons or the Access
window's close button were used. There may be an API call to trap these, I
don't know.

Here is one example of the information from the help file. It gets much
longer because of the possible combinations of things you may be trying to
do.
-------------------------------------------------
When you move the focus to an existing record on a form, enter or change
data in the record, and then move the focus to another record, the following
sequence of events occurs for the form:

Current (form) ? BeforeUpdate (form) ? AfterUpdate (form) ? Current (form)

When you leave the record whose data has changed, but before you enter the
next record, the Exit and LostFocus events occur for the control with the
focus. These events occur after the BeforeUpdate and AfterUpdate events for
the form, as follows:

BeforeUpdate (form) ? AfterUpdate (form) ? Exit (control) ? LostFocus
(control) ? RecordExit (form) ? Current (form)

As you move the focus among the controls on a form, events occur for each
control. For example, the following sequences of events occur when you:

Open a form and change data in a control:
Current (form) ? Enter (control) ? GotFocus (control) ? BeforeUpdate
(control) ? AfterUpdate (control)

Move the focus to another control:
Exit (control1) ? LostFocus (control1) ? Enter (control2) ? GotFocus
(control2)

Move the focus to another record:
BeforeUpdate (form) ? AfterUpdate (form) ? Exit (control2) ? LostFocus
(control2) ? RecordExit (form) ? Current (form)

Deleting records
When you delete a record, the following events occur for the form, and
Microsoft Access displays a dialog box asking you to confirm the deletion:
Delete ? BeforeDelConfirm ? AfterDelConfirm

If you cancel the Delete event, the BeforeDelConfirm and AfterDelConfirm
events don't occur and the dialog box isn't displayed.
 
Sheldon said:
Which event(s) get fired and in which order when the
following buttons are clicked

1. The previous record button on a navigation control,
2. The next record record btton on a navigation control,
3. The create new record button on a navigation control,
4. The goto first record on a navigation control,
5. The goto last record on a navigation control,
5. The "X" control on the top of the form near the
min/max button.

Also can you determine in code which of the above was
clicked.


Lots of events fire as a result of any of those actions,
which ones depend on what was going on before the action.
Unfortunately, there are no events that fire to indicate
exactly which action was taken. Most of the events (e.g.
Before/After Update) fire before the navigation occurs, but
the Current event occurs after the navigation.

You can determine what the sequence of events by creating a
test form with event procedures for every possible event and
adding Debug.Print or MsgBox statements to each of them.
Then perform various activities, such as dirtying a record
and clicking a navigation button.
 
Back
Top