ADO » Connection » WillConnect

WillConnect ConnectionString, UserID, Password, Options, adStatus, pConnection
The ConnectionString parameter is a string that contains the information required for the pending connection.
The UserID parameter is a string containing the user name to use when making the connection.
The Password parameter is a string containing the password to use when making the connection.
The Options parameter is a long value that represents the options passed into the Open method of the Connection object. It can only be set to the adAsyncOpen constant.
The adStatus parameter defines the status of the event and is one of the EventStatusEnum constants. Before the event returns, to prevent unwanted future firings of this event, set this parameter to adStatusUnwantedEvent.
The pConnection parameter is the Connection object that is associated with the execution.

This event can be called before the connection starts.You can change any of the parameters and even cancel the connection.

The WillConnect event can be fired just before a connection attempt is made. This event is one of three connection management events that can be called. The other two events are ConnectComplete and Disconnect.
An event is simply a subroutine that can be called automatically after a specific operation has occurred. This subroutine can contain any code that you need to run when the event occurs. The subroutine will only be called if it is included in your code. Future calls to the event subroutine can be cancelled by setting the adStatus parameter to be the adStatusUnwantedEvent constant (see table below) before the event returns.
There are six parameters that are passed to this event.
EventStatusEnum Constants

Constant Value Description
adStatusCancel 4 Cancels the operation that fired the event
adStatusCantDeny 3 Cannot cancel pending operation
adStatusErrorsOccurred 2 Indicates that warnings and/or errors occurred
adStatusOK 1 The operation that fired the event was successful
adStatusUnwantedEvent 5 The operation that generated the event cannot generate future events


' Use the WithEvents keyword to designate that events
' can be handled by this Connection object
Dim WithEvents objConn As ADODB.Connection

' Note how the object name, objConn, is incorporated into the event Sub name
Private Sub objConn_WillConnect( ConnectionString As String, _
   UserID As String, _
   Password As String _
   Options As Long, _
   adStatus As ADODB.EventStatusEnum, _
   ByVal pConnection As ADODB.Connection )

' place any code you desire here, for example
If UserID = "test" Then
   Print "Connection String = " & ConnectionString
End If

End Sub

See Also: