User Form events

Several events are associated with showing and unloading a UserForm:

■ Initialize: Occurs before a UserForm is loaded or shown but does not occur if the UserForm was previously hidden.

■ Activate: Occurs when a UserForm is shown.

■ Deactivate: Occurs when a UserForm is deactivated but does not occur if the form is hidden.

■ QueryClose: Occurs before a UserForm is unloaded.

■ Terminate: Occurs after the UserForm is unloaded.

Note 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.

CD- The companion CD-ROM contains a workbook (named % )

ROM 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.

0 0

Post a comment