OnClick, OnOpen, OnCurrent... Events

Events can be used to trigger a Macro or a block of VBA code. The most common event is OnClick but there are many other listed below for Forms and TextBoxes:

Form Events:

.OnActivate - The form or report receives the focus and becomes the active window.
.OnApplyFilter - A filter is applied or removed.
.OnClick - A user presses and releases the left mouse button over an object.
.OnClose - A form or report is closed and removed from the screen.
.OnConnect -
.OnCurrent - Focus moves to a record, making it the current record, or when the form is refreshed or requeried.
.OnDblClick - A user presses and releases the left mouse button twice over an object
.OnDeactivate - The form or report loses the focus to different form or report (or any other database object).
.OnDelete - The user performs some action, such as pressing the DELETE key, but before the record is actually deleted.
.OnDirty - The contents of a form or the text portion of a combo box change. It also occurs when moving between pages in a tab control.
.OnDisconnect -
.OnError - A run-time error is produced in Access when the form has the focus. This includes Jet database engine errors, but not VBA run-time errors.
.OnFilter - A form is opened and its records are displayed.
.OnGotFocus - The object receives focus.
.OnInsert - The BeforeInsert event occurs when the user types the first character in a new record, but before the record is actually created.
.OnKeyDown - A user presses a key while a form or control has the focus.
.OnKeyPress - A user presses a key while a form or control has the focus.
.OnKeyUp - A user releases a key while a form or control has the focus.
.OnLoad - A form is opened and its records are displayed.
.OnLostFocus - The object loses the focus.
.OnMouseDown - The user clicks the mouse button while the mouse pointer rests over the object.
.OnMouseMove - The user moves the mouse over the object.
.OnMouseUp - The user releases a mouse button.
.OnOpen - A form/report is opened, but before the first record is displayed.
.OnResize - A form is opened and whenever the size of a form changes.
.OnTimer - Occurs for a form at regular intervals as specified by the TimerInterval property.
.OnUndo - The user undoes a change.
.OnUnload - A form is closed but before it is removed from the screen.

TextBox events

.AfterUpdate - After data is changed in a control or a record is updated.
.BeforeUpdate - Occurs before changed data in a control or record is updated.
.Change - Occurs when the contents of the specified control changes.
.Click - A user presses and releases the left mouse button over an object.
.DblClick - A user presses and releases the left mouse button twice over an object
.Dirty - The contents of the specified control changes. (programmatic changes don’t trigger this event)
.Enter - Occurs before a control receives the focus from a control on the same form/ report (.Enter happens before .GotFocus).
.Exit - Occurs before a control loses the focus to a control on the same form/ report (.Exit happens before .LostFocus).
.GotFocus - The object receives focus.
.OnKeyDown - A user presses a key while a form or control has the focus.
.OnKeyPress - A user presses a key while a form or control has the focus.
.OnKeyUp - A user releases a key while a form or control has the focus.
.LostFocus - The object loses the focus.
.MouseDown - The user clicks the mouse button while the mouse pointer rests over the object.
.OnMouseMove - The user moves the mouse over the object.
.MouseMove - The user moves the mouse over the object.
.MouseUp - The user releases a mouse button.
.Undo - The user undoes a change.

The value of these events can be read from VBA and (if set) will be "[Event Procedure]" or MacroName or "=expression"

Similar events are triggered for most other form/report objects (comboboxes, tickboxes etc)

The order of events when opening and closing a form:
 
   OnOpen > OnLoad > Activate > OnCurrent > DeActivate > OnUnLoad > OnClose

 Load into Display   Has focus  Populate     Lost focus  Remove      Remove
  memory   on screen           current record            from screen from memory

Now, because of this order of operations, you can cancel an OnOpen event, but not an OnLoad (as it’s already open), and similarly you can cancel an OnUnLoad but not an OnClose.

“The hours of folly are measured by the clock, but of wisdom no clock can measure” ~ William Blake

Related

.CancelEvent - Cancel an event.
DoEvents - Allow the operating system to process other events.


 
Copyright © 1999-2024 SS64.com
Some rights reserved