Microsoft Office Tutorials and References
In Depth Information
Understanding UserForm Events
h Deactivate : Occurs when a UserForm is deactivated but doesn’t occur if the form is
hidden.
h QueryClose : Occurs before a UserForm is unloaded.
h Terminate : Occurs after the UserForm is unloaded.
Often, it‘s critical that you choose the appropriate event for your event-handler
procedure and that you understand the order in which the events occur. Using the Show
method invokes the Initialize and Activate events (in that order). Using the Load
command invokes only the Initialize event. Using the Unload command triggers
the QueryClose and Terminate events (in that order). Using the Hide method
doesn’t trigger either of these events.
The companion CD-ROM contains a workbook (named userform events.xlsm ) that
monitors all these events and displays a message box when an event occurs. If you’re
confused about UserForm events, studying the code in this example should clear things up.
SpinButton events
To help clarify the concept of events, this section takes a close look at the events associated with
a SpinButton control. Some of these events are associated with other controls, and some are
unique to the SpinButton control.
The companion CD-ROM contains a workbook that demonstrates the sequence of
events that occur for a SpinButton and the UserForm that contains it. The workbook,
named spinbutton events.xlsm , contains a series of event-handler routines — one
for each SpinButton and UserForm event. Each of these routines simply displays a
message box that tells you the event that just fired.
Table 13-1 lists all the events for the SpinButton control.
Table 13-1: SpinButton Events
Event
Description
AfterUpdate
Occurs after the control is changed through the user interface.
BeforeDragOver
Occurs when a drag-and-drop operation is in progress.
BeforeDropOrPaste
Occurs when the user is about to drop or paste data onto the control.
BeforeUpdate
Occurs before the control is changed.
Change
Occurs when the Value property changes.
Enter
Occurs before the control actually receives the focus from a control on the
same UserForm.
 
Search JabSto ::




Custom Search