Hi,
I have a little problem with a macro I'm working at. I need to pull data from a database and then show it in an excel sheet. Everything work fine till the moment when I want to close the recordset . Then my application freezes and I have to kill the process from Task Manager.
Here is the code
Dim spBasicInfo As ADODB.Command
Dim rsBasicInfo As ADODB.Recordset
... 'some code
On Error GoTo err_place
Set_Connection
Set spBasicInfo = New ADODB.Command
Set rsBasicInfo = New ADODB.Recordset
With spBasicInfo
.ActiveConnection = dbConnection
.CommandType = adCmdText
.CommandText = "Raport_contacte_ora"
.CommandTimeout = 10000
.Parameters.Append .CreateParameter("@year", adInteger, adParamInput, 4, objCmdEdit.Text)
End With
rsBasicInfo.Open spBasicInfo, , adOpenStatic, adLockReadOnly, adCmdStoredProc
Do While ((rsBasicInfo.State And adStateOpen) <> adStateOpen)
Set rsBasicInfo = rsBasicInfo.NextRecordset()
If (rsBasicInfo Is Nothing) Then Exit Do
Loop
If rsBasicInfo.EOF And rsBasicInfo.BOF Then
Exit Sub
End If
Application.ScreenUpdating = False
With rsBasicInfo
i = 3
Do While Not .EOF
'some proccesing
.MoveNext
Loop
End With
... 'formatting
err_place:
If Err.Number <> 0 Then
MsgBox "Error", vbCritical, "Raport_ore_locatie"
Else: MsgBox "Success!", vbInformation, "Raport_ore_locatie"
End If
err_delete:
'save
If (rsBasicInfo.State = adStateOpen) Then
rsBasicInfo.Close 'here it stops
End If
Set rsBasicInfo = Nothing
Set dbConnection = Nothing
I use Excel 2002 with Microsoft VB 6.3, MSSQL 2005.
The recordset has at least 10000 records(maybe helps to know).
Thank you,
Ionut