I am trying to export over 10,000 records to excel using the following code. It runs fine when I have a normal amount of records but when I run the sproc the way it is to run live (over 10,000 records) the program locks up. Is there a maximum number of records that a recordset can hold? Is there any way to fix it?
VB Code:
My Stored Procedure
VB Code:
Code:
Private Sub mnuTaxFormApprovalReport_Click()
On Error GoTo HandleError
Dim poCatalogContact As TrxObject.clsReports
Dim lrsTaxFormReportData As ADODB.Recordset
Set lrsTaxFormReportData = New ADODB.Recordset
Set poCatalogContact = New TrxObject.clsReports
Set lrsTaxFormReportData = poCatalogContact.GetTaxFormApprovalReport()
Dim strBuffer As String
Dim fld As Field
Dim objExcel As Excel.Application
strBuffer = "Return Code" & vbTab
strBuffer = strBuffer & "Tax Return ID" & vbTab
strBuffer = strBuffer & "Form Description" & vbTab
strBuffer = strBuffer & "Contact Name" & vbTab
strBuffer = strBuffer & "Contact #" & vbTab
strBuffer = strBuffer & "Email" & vbTab
strBuffer = strBuffer & "Address1" & vbTab
strBuffer = strBuffer & "Address2" & vbTab
strBuffer = strBuffer & "State" & vbTab
strBuffer = strBuffer & "County" & vbTab
strBuffer = strBuffer & "City" & vbTab
strBuffer = strBuffer & "Zip" & vbTab
strBuffer = strBuffer & "First Approval Date" & vbTab
strBuffer = strBuffer & "Last Approval Date" & vbTab
strBuffer = strBuffer & "Next Approval Date" & vbCrLf
' Copy Recordset to string buffer
lrsTaxFormReportData.MoveFirst
Do While Not lrsTaxFormReportData.EOF
For Each fld In lrsTaxFormReportData.Fields
strBuffer = strBuffer & fld.Value & vbTab
Next fld
If strBuffer <> "" Then
strBuffer = Left(strBuffer, Len(strBuffer) - 1)
End If
strBuffer = strBuffer & vbCrLf
lrsTaxFormReportData.MoveNext
Loop
' Copy Stringbuffer to clipboard
Clipboard.Clear
Clipboard.SetText strBuffer
' Insert clipboard in excel
Set objExcel = New Excel.Application
objExcel.Visible = True
objExcel.Workbooks.Add
'******************************************************
objExcel.ActiveSheet.Range("A1:O1").Font.Bold = True
'*****************************************************
objExcel.ActiveSheet.Paste
Set lrsTaxFormReportData = Nothing
Exit Sub
HandleError:
Dim liReturnValue As Integer
liReturnValue = CentralErrorHandler(Err.Number, "mnuReportsTaxReturn_Click", _
"frmMain", "TRACS.vbp")
If liReturnValue = 0 Then
Resume
ElseIf liReturnValue = 1 Then
Resume Next
ElseIf liReturnValue = 2 Then
Exit Sub
End If
End Sub
My Stored Procedure
Code:
CREATE PROCEDURE dbo.cas_TaxApprovalContactRpt
AS
SELECT Catalog.RtnCode,
Catalog.TaxRtnID,
Catalog.Descript,
CatalogTaxFormContactInfo.ContactName,
CatalogTaxFormContactInfo.ContactNum,
CatalogTaxFormContactInfo.ContactEmail,
CatalogTaxFormContactInfo.ContactAdd1,
CatalogTaxFormContactInfo.ContactAdd2,
CatalogTaxFormContactInfo.ContactState,
CatalogTaxFormContactInfo.ContactCounty,
CatalogTaxFormContactInfo.ContactCity,
CatalogTaxFormContactInfo.ContactZip,
CatalogTaxFormContactInfo.FirstAppDate,
CatalogTaxFormContactInfo.LastAppDate,
CatalogTaxFormContactInfo.NextAppDate
FROM Catalog
Inner Join CatalogTaxFormContactInfo
on CatalogTaxFormContactInfo.CatalogID = Catalog.CatalogID
Order By IsNull(NextAppDate, '30000101') ASC, RtnCode ASC