Table of Contents

VBC09326 — Invalid event handler

Severity: Error  ·  Family: VBC (static semantics / abstract syntax tree)  ·  Source metadata: VBCompileErrorInfo

A procedure that is named as the handler of an event is not a valid one.

MS-VBAL §5.3.1.8 Event Handler Declarations makes a procedure of a class module the handler of an event when its name is VariableName_EventName: the name of a WithEvents variable of the same module, then an underscore, then the name of an event of the class that variable is declared as. Such a handler is invalid when it is not a subroutine, or when its parameter list is not compatible with the parameter list of the event.

This code is raised by ClassModuleEventSemantics. The verbose detail names the handler, the event, and what does not match.

How it is raised

Situation Example, for Event Changed(ByVal Value As Long) of Src Resolution
The handler is a function or a property. Private Function Src_Changed(ByVal Value As Long) As Long Declare a subroutine.
The handler has another number of parameters. Private Sub Src_Changed() Give it the event's parameters.
A parameter is of another type. Private Sub Src_Changed(ByVal Value As String) Declare the event's type.
A parameter is passed by another mechanism. Private Sub Src_Changed(ByRef Value As Long) Pass it the way the event does.

Notes

A compatible parameter list may differ from the event's in the names of its parameters, and in whether the mechanism is written out: Count As Long handles ByRef Count As Long.

An Enum is the declared type Long, so a parameter declared Long is of the type of an event's parameter declared as an Enum, and the other way round, as is one of another Enum (RD-VBAL §5.2.3.4).

A procedure whose name begins with the name of a WithEvents variable and an underscore, but does not end with the name of an event of the variable's class, is not a handler of anything, and is not checked. Neither is one named for a variable that is not declared WithEvents.

The controls of a UserForm are WithEvents variables of the form's class, so TextBox1_Change handles the Change event of TextBox1. A handler of a control's event that does not match the event is not this error: MS-VBA compiles it (recorded in Excel), and the event never calls it. RD-VBA reports it as the dead code it is, RDC00407 Unmatched event handler, unless the form's own code calls it.

See also


⏮️ VBC09325 Invalid event name | ⏭️ VBC09327 ByVal argument not allowed here


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca