The ConnectionEvent Family
The ConnectionEvent family contains a group of events that belong to the Connection object. To instantiate a connection object that implements events, declare it as follows:
Private WithEvents con As ADODB.Connection
As stated earlier, the events within the ConnectionEvent family can be broken into four categories:
Connection events
Execution events
Transaction events
Informational events
Each category of events contains events pertaining to one specific task.
Connection Events
The Connection events category of the ConnectionEvent family comprises three events:
The WillConnect event is raised when a connection to a data source is about to be attempted.
The ConnectComplete event is raised after a connection to a data source has been attempted.
The Disconnect event is raised after a connection to a data source has been terminated.
The WillConnect and ConnectComplete events are a Will/Complete event pair. Notice there is not a Will event for the Disconnect event, making it a standalone event.
To illustrate when each of these events is fired, enter a call to the PrintStatus function (which I will describe in a minute) to the three events:
Private Sub con_WillConnect(ConnectionString As String, _ UserID As String, _ Password As String, _ Options As Long, _ adStatus As ADODB.EventStatusEnum, _ ByVal pConnection As ADODB.Connection) PrintStatus "WillConnect", adStatus End Sub Private Sub con_ConnectComplete(ByVal pError As ADODB.Error, _ adStatus As ADODB.EventStatusEnum, ...
Get ADO: ActiveX Data Objects now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.