Chapter 1 -- 12
Programmer’s Guide
S A WithEvents variable cannot be a generic object variable.
Thatis,youcannotdeclareitAsObject-youmustspecify
the class name when you declare the variable.
S You cannot declare a WithEvents variable As New. The
event source object must be explicitly created and assigned
to the WithEvents variable.
S You cannot declare WithEvents variables in a standard mod-
ule. You can declare them only in class modules, form mod-
ules, a nd other mod ule s that define classes.
S You cannot create arrays of WithEvents variables.
"
""
" Writing code to handle an event
As soon as you declare a variable WithEvents,thevariable
name appears in the left-hand drop down of the module’s code
window. When you select MyDoc,theDocument class events
will appear in the right-hand drop down, as shown in Figure 2
below:
Figure 2 An event associated with a WithEvents variable
Selecting an event will display the corresponding event
procedure, with the prefix MyDoc_. All the e vent procedures
associated with a WithEvents variable will have the variable
name as a prefix.