PRB: Error 3712 with the ExecuteComplete EventID: Q229799
|
When you execute an ActiveX Data Object (ADO) command asynchronously, the ExecuteComplete event may generate Error 3712 as follows:
Operation has been cancelled by the user
The scope of the command object is private to the procedure in which it appears. This would cause the command object to be released prior to calling the ExecuteComplete event (goes out of scope).
Use a command object with a broader scope, one that would be available to the ExecuteComplete event.
This behavior is by design.
The ExecuteComplete event is called after a command has finished executing, when all asynchronous phases for that operation have completed. If the asynchronous operation was successful or was aborted by the user, the adStatus parameter is set to adStatusOK. Otherwise, it would be set to adStatusErrorsOccurred if the operation failed, or was aborted by the consumer.
Option Explicit
Dim WithEvents cn As ADODB.Connection
Private Sub Command1_Click()
Dim Cmd As New ADODB.Command
Dim ConStr As String
Set cn = New ADODB.Connection
ConStr = "Provider=SQLOLEDB.1;Data Source=<YourServerName>;user id=<YourUserID>;Password=<YourPassword>;Initial Catalog=Pubs;"
cn.Open ConStr
With Cmd
Set .ActiveConnection = cn
.CommandType = adCmdText
.CommandText = "Select * From Authors"
.Execute , , adAsyncExecute
End With
End Sub
Private Sub cn_ExecuteComplete(ByVal 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)
'check for errors during the asynchronous operation
If (adStatus = adStatusErrorsOccurred) Then
MsgBox "Error # " & pError.Number & vbCrLf & pError.Description
End If
End Sub
Additional query words: kbdse
Keywords : kbADO kbDatabase kbVBp kbGrpVBDB
Version : WINDOWS:2.0,2.01,2.1,6.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: May 28, 1999