ADO WillExecute and ExecuteComplete Events

Definition and Usage

The event is an automatically called subroutine after a specific operation occurs.

  • The WillExecute event is triggered before calling objcomm.Execute, objconn.Execute, or objrs.Open.
  • The ExecuteComplete event is triggered after the call to objcomm.Execute, objconn.Execute, objrs.Open, objrs.Requery, or objrs.NextRecordset is completed.

Syntax

WillExecute src,cursortyp,locktyp,options,status,objcomm,objrs,objconn
ExecuteComplete refactored,objerror,status,objcomm,objrs,objconn
parameter Description
src A string containing the SQL command or stored procedure name.
cursortyp specifies the cursor type to be used.CursorTypeEnum one of the values.
locktyp specifies the locking type to be used.LockTypeEnum one of the values.
options one or more CommandTypeEnum or ExecuteOptionEnum Value
reaffected A Long value representing the number of records affected by the command.
objerror Contains the Error object with the errors that have occurred.

Note: The EventStatusEnum value must be set to adStatusErrorsOccurred to create the Error object.

status one EventStatusEnum value.
objcomm

For WillExecute: If this event is triggered by Command.Execute, the objcomm parameter will refer to the Command object, and the objrs parameter will be set to Nothing.

For ExecuteComplete: The executed Command object.

objrs

For WillExecute: If this event is triggered by Recordset.Open, the objrs parameter will refer to the Recordset object, and the pCommand parameter will be set to Nothing.

For ExecuteComplete: Recordset object, it is the result of command execution.

objconn The Connection object associated with command execution.

EventStatusEnum Values

Constant Value Description
adStatusOK 1 The operation that triggered this event was successful.
adStatusErrorsOccurred 2 The operation that triggered this event failed.
adStatusCantDeny 3 Cannot cancel suspended operations.
adStatusCancel 4 Cancel the operation that caused the event to occur.
adStatusUnwantedEvent 5 Prevent subsequent notifications before the event method execution is completed.