Event Properties

Event properties are the driving force behind the automation of a form. These properties are the reaction to a situation triggered by the user. Examples include clicking a command button, updating a text box, or entering a value that does not exist in a combo box. Anytime the user triggers one of these actions, the programmer must react appropriately to perform tasks such as opening another form (or report), sending an e-mail, and/or data validation. The possibilities of what can be performed are endless, but they all start with an event property.

The following table displays some of the frequently used event properties and what causes them to be executed. Some of these properties will be demonstrated in the code samples later in the chapter.

Property

Triggers when . . .

On Open

The form is opened (can be cancelled)

On Close

The form is closed

On Load

The form loads

On Unload

The form unloads (can be cancelled)

On Click

A section of the form or a control is clicked, once, by the mouse

On Dbl Click

A section of the form or a control is clicked, twice, by the mouse

On Current

A record is loaded into the form (think of it as 'On Current Record')

On Dirty

The user makes any modification to the current record

Before Update

Before the update is committed to the form or control (can be cancelled)

After Update

A form record or an individual control is updated

On Change

A value on a control is modified

On Timer

The TimerInterval property reaches a specified value

Not In List

The user enters a value that is not in a combo box

On Mouse Move

The mouse is moved over a section of the form or a control

On Enter

The user physically places cursor into the control. This can be accomplished with the Tab or Enter key, or by a click of the mouse

Just like the regular properties (that is, BackColor, Visible, or AllowEdits), Forms have their own set of event properties, and each control on that Form has its own as well. The items in the list above represent a cross section of event properties that exist for Forms and Controls. Not all controls have the same event properties as a Form, and depending on the type of control, it may have additional event properties to handle specific situations that only exist for that control. For example, a combo box (a control with which the user can select an existing value, or enter one not available) has a LimitToList property that restricts the user to only selecting a value that exists. If the user does not select or enter a valid value from this property, then the NotInList event property will trigger, and the programmer can add code to react to it.

Knowing what event properties are available and knowing when they will execute is the heart of VBA programming. Another tidbit to launch you forward is that some event properties can be cancelled, while others may not. Learning these three elements will take some time, but just knowing that they are there is a good start.

0 0

Post a comment