After a command has finished executing, you can call this event to provide information on the successof the command and the number of records affected.
The ExecuteComplete event can be fired after either a Command.Execute, Connection.Execute,
Recordset.Open, Recordset.Requery, or Recordset.NextRecordset method has completed execution.
This event is one of two command execution management events that can be called.
The other event is WillExecute.
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_ExecuteComplete( RecordsAffected As Long, _
ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pCommand As ADODB.Command, _
ByVal pRecordset As ADODB.Recordset, _
ByVal pConnection As ADODB.Connection )
' place any code you desire here, for example
If adStatus = adStatusOK Then
Print "Records affected = " & RecordAffected
Else
Print "ExecuteComplete Status = " & adStatus
End If
End Sub