When we added an ActiveX control to the form, VB automatically added the event handler stubs to the development environment of the form and passed the events raised by the control to the client application. ActiveX code components can do this as well, but only if they are declared in the Declarations section of the module using the WithEvents keyword. This keyword cannot be used unless the variable is declared using early binding techniques. Here is an example using the WithEvents keyword with the Access Data Objects component (note the event handler stubs are available in the VB IDE after declaring the AdoRS variable:
‘Declarations Section
‘--------------------
‘
‘*** Create an Object Reference variable such
‘*** that events are generated in Visual Basic
‘*** from the object.
Dim WithEvents AdoRS as ADODB.Recordset