activex_data_objects thread: Canceling Async Fetch Recordset (posted in 3 other newsgroups without response. Please help!)
I am opening an ado recordset asynchronously. I give the users the ability
to cancel the fetch if they want to. Depending on the query, it is taking a
long time (30 sec to minute) to come back with a message saying that the
fetch has been cancelled. Do I need to wait for the message or can I just
set the recordset = nothing after executing the cancel method? Here is my
code:
'Code to start the fetch
Set rsWorkSheet = New ADODB.Recordset
rsWorkSheet.CacheSize = 100
rsWorkSheet.CursorLocation = adUseClient
'The next 2 properties are used for the FetchProgress event
rsWorkSheet.Properties("Initial Fetch Size") = 101
rsWorkSheet.Properties("Background Fetch Size") = 1000
rsWorkSheet.Open sSQL, oCnn, adOpenStatic, adLockReadOnly, adAsyncFetch
'Code to Cancel
rsWorkSheet.Cancel
'Code to wait for message
Private Sub rsWorkSheet_FetchComplete(ByVal pError As ADODB.Error, adStatus
As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo rsWorkSheet_FetchComplete_Error
Select Case adStatus
Case adStatusOK
'data is processed here
Case adStatusCancel
MsgBox "Operation cancelled by user!", vbInformation, AppTitle
Case adStatusErrorsOccurred
If pError.Number = -2147217842 Then
MsgBox "Operation cancelled by user!", vbInformation, AppTitle
Else
MsgBox pError.Number & "-" & pError.Description, vbInformation,
AppTitle
End If
End Select
Any help would be great.
Thanks,
Daniel Reber