Export (0) Print
Expand All

Adding Events to Custom Classes

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

You can include your own events in custom classes, and create event procedures that run when those events occur. Creating a custom event is somewhat more complex than creating an event procedure for a built-in event, because your code has to raise the custom event in response to something that happens within the code.

In This Section

Understanding Custom Events
When you raise an event, you cause its event procedure to run.
When Do You Need to Create a Custom Event?
In many cases, it is not necessary to create a custom event — you can call a procedure to do the same thing.
Creating Custom Events
The DataComboBox object wraps a combo box on a form to provide an additional event, the ItemAdded event, which the MSForms ComboBox control does not have.

Related Sections

Creating Events and Event Procedures
Take advantage of simple to create events procedures and use ThisDocument, ThisWorkbook, or SheetN objects.
Creating Event Procedures for Built-in Events by Using the WithEvents Keyword
The objects for which you have commonly written event procedures — UserForms, Microsoft® Access forms and reports, and the ThisDocument, ThisWorkbook, and SheetN objects — all have an associated class module.
Show:
© 2014 Microsoft