473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Recordset RecordCount returning Error 6 Overflow

I have a command button that pulls an Adobe RecordSet and Exports the data to Excel. One of my users reports getting Error 6 Overflow when running the export for a particular criteria. I thought that it was because the recordset contained too many records, but when I look at the records for the criteria there is currently 44,461 records and Microsoft allows me to export these manually.

I stepped through the code and found that it fails on this line.
Expand|Select|Wrap|Line Numbers
  1. iRow = rst.RecordCount + 1
The code operates correctly for other criteria. Do you know of a solution to this issue?

This is the full code for the Command Button.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_XprtXls_Click()
  2. On Error GoTo Err_cmd_XprtXls_Click
  3.  
  4.     Dim Conn As ADODB.Connection
  5.     Dim stPath As String
  6.     Dim rst As ADODB.Recordset
  7.     Dim sSQL As String
  8.     Dim stErrMsg As String
  9.     Dim sSelect As String
  10.     Dim sFrom As String
  11.     Dim sGroupBy As String
  12.     Dim sHaving As String
  13.     Dim sOrder As String
  14.     Dim DblYr As Double
  15.     Dim DblMn As Double
  16.     Dim sPM As String
  17.     Dim sROGT As String
  18.     Dim stPrjt As String
  19.     Dim sSbprjtGrp As String
  20.     Dim stSbprjt As String
  21.     Dim stOrg As String
  22.     Dim stAct As String
  23.     Dim xlApp As Object
  24.     Dim xlWb As Object
  25.     Dim xlWs As Object
  26.     Dim acRng As Variant
  27.     Dim iRow As Integer
  28.  
  29.     DoCmd.Hourglass True
  30. '    Debug.Print Me.Name & " Start Export: " & Now()
  31.  
  32.     stErrMsg = ""
  33.     If IsNull(Me.cmb_ExpYr.Value) Then
  34.         stErrMsg = stErrMsg & vbCrLf & "Year"
  35.     End If
  36.     If IsNull(Me.cmb_ExpMnth.Value) Then
  37.         stErrMsg = stErrMsg & vbCrLf & "Month"
  38.     End If
  39.  
  40. '12/15/14 Requirements Changed per PMaC development group
  41.     If Not IsNull(Me.cmb_PM) And IsNull(Me.cmbRptOwnerGrpTitle) Then
  42.         strErrMsg = strErrMsg & vbCrLf & "Favorites is required when PM/Report Owner is selected"
  43.     End If
  44.  
  45.     If IsNull(Me.cmb_ProjectID.Value) Then
  46.         stErrMsg = stErrMsg & vbCrLf & "Project"
  47.     End If
  48.  
  49.     If stErrMsg <> "" Then
  50.         MsgBox "Please select the required information." & vbCrLf & stErrMsg, vbExclamation + vbOKOnly, "Missing Information"
  51.         DoCmd.Hourglass False
  52.         Exit Sub
  53.     End If
  54.  
  55.     'Set the query parameter values
  56.     DblYr = Me.cmb_ExpYr.Value
  57.     DblMn = Me.cmb_ExpMnth.Value
  58.     stPrjt = Me.cmb_ProjectID
  59.     ' 12/15/14
  60.     If IsNull(Me.cmb_PM) Then
  61.         sPM = "'%'"
  62.         sROGT = "%"
  63.     Else
  64.         sPM = Me.cmb_PM
  65.         sROGT = Me.cmbRptOwnerGrpTitle
  66.     End If
  67.  
  68.     If IsNull(Me.cmbSbprjtGrp.Value) Then
  69.         sSbprjtGrp = "%"
  70.     Else
  71.         sSbprjtGrp = Me.cmbSbprjtGrp.Value
  72.     End If
  73.     If IsNull(Me.cmb_SubprojectID) Then
  74.         stSbprjt = "%"
  75.     Else
  76.         stSbprjt = Me.cmb_SubprojectID
  77.     End If
  78.     If IsNull(Me.cmb_ActivityID) Then
  79.         stAct = "%"
  80.     Else
  81.         stAct = Me.cmb_ActivityID
  82.     End If
  83.     If IsNull(Me.cmb_OrgGrp) Then
  84.         stOrg = "%"
  85.     Else
  86.         stOrg = Me.cmb_OrgGrp
  87.     End If
  88.  
  89.     sSelect = "SELECT [LTD]![ProjectDescription] AS [Project ID - Description]" _
  90.         & ", [LTD]![SUBPROJECTDESCRIPTION] AS [Subproject ID - Description]" _
  91.         & ", [LTD]![ActivityDESCR] AS [Activity ID - Description]" _
  92.         & ", [LTD]![PROJECT_TO] AS [Funding Project ID - Description]" _
  93.         & ", [LTD]![SUBPROJECT_TO] AS [Funding Subproject ID - Description]" _
  94.         & ", [LTD]![Activity_To] AS [Funding Activity ID - Description]" _
  95.         & ", LTD.VndrEmpName AS Name, [LTD]![Phase] & ' - ' & [tblPhaseDescr]![Description] AS Phase" _
  96.         & ", LTD.Organization AS [Org - Description]" _
  97.         & ", LTD.OrgGrp AS [Org Group]" _
  98.         & ", LTD.Labor AS [Account Group]" _
  99.         & ", LTD.FiscalYear AS [Year]" _
  100.         & ", LTD.AccountingPeriod AS [Month]" _
  101.         & ", Sum(IIf([LTD]![FiscalYear]= " & DblYr & " And [LTD]![AccountingPeriod]= " & DblMn & ",[LTD]![EXPENDITURES],0)) AS [Current Month Amt]" _
  102.         & ", Sum(IIf([LTD]![FiscalYear]= " & DblYr & " And [LTD]![AccountingPeriod]<= " & DblMn & ",[LTD]![EXPENDITURES],0)) AS [Year to Date Amt]" _
  103.         & ", Sum(IIf([LTD]![FiscalYear]= " & DblYr & " And [LTD]![AccountingPeriod]<= " & DblMn & ",[LTD]![EXPENDITURES],IIf([LTD]![FiscalYear]<= " & DblYr & ",[LTD]![EXPENDITURES],0))) AS [Life To Date Amt]" _
  104.         & ", Sum(IIf([LTD]![FiscalYear]= " & DblYr & " And [LTD]![AccountingPeriod]= " & DblMn & ",[LTD]![Hours],0)) AS [Current Month Hrs]" _
  105.         & ", Sum(IIf([LTD]![FiscalYear]= " & DblYr & " And [LTD]![AccountingPeriod]<= " & DblMn & ",[LTD]![Hours],0)) AS [Year to Date Hrs]" _
  106.         & ", Sum(IIf([LTD]![FiscalYear]= " & DblYr & " And [LTD]![AccountingPeriod]<= " & DblMn & ",[LTD]![Hours],IIf([LTD]![FiscalYear]<" & DblYr & ",[LTD]![Hours],0))) AS [Life To Date Hrs]"
  107.  
  108.     sFrom = "FROM (SELECT Trim([zqselMngrSbprjtRptGrpSbprjtFltr_Exp]![SubprojectID]) AS SubprojectID" _
  109.                         & " FROM zqselMngrSbprjtRptGrpSbprjtFltr_Exp" _
  110.                         & " WHERE (((IIf([zqselMngrSbprjtRptGrpSbprjtFltr_Exp]![GROUPINGCODE] Is Null,'ZZZ',[zqselMngrSbprjtRptGrpSbprjtFltr_Exp]![GROUPINGCODE]) ALike '" & sSbprjtGrp & "'))" _
  111.                         & " AND ((IIf([zqselMngrSbprjtRptGrpSbprjtFltr_Exp]![RPTGRPTITLE] Is Null,'ZZZ',[zqselMngrSbprjtRptGrpSbprjtFltr_Exp]![RPTGRPTITLE]) ALike '" & sROGT & "'))" _
  112.                         & " AND ((IIf([zqselMngrSbprjtRptGrpSbprjtFltr_Exp]![RptOwnerID] Is Null,0,[zqselMngrSbprjtRptGrpSbprjtFltr_Exp]![RptOwnerID])) ALike " & sPM & ")" _
  113.                         & " AND ((zqselMngrSbprjtRptGrpSbprjtFltr_Exp.PROJECTID ALike '" & stPrjt & "')))" _
  114.                         & " GROUP BY Trim([zqselMngrSbprjtRptGrpSbprjtFltr_Exp]![SubprojectID])" _
  115.                         & " HAVING (((Trim([zqselMngrSbprjtRptGrpSbprjtFltr_Exp]![SubprojectID])) ALike '" & stSbprjt & "'))) AS qrptSbPrjtLTDPrgmCMYTDLTDSbprjtFltrd" _
  116.                 & " LEFT JOIN (tblPrjtLTDExpndRptBase AS LTD " _
  117.                 & " LEFT JOIN tblPhaseDescr ON LTD.Phase = tblPhaseDescr.PHASE)" _
  118.             & " ON qrptSbPrjtLTDPrgmCMYTDLTDSbprjtFltrd.SubprojectID = LTD.SUBPROJECTID"
  119.  
  120.     sGroupBy = " GROUP BY [LTD]![ProjectDescription]" _
  121.         & ", [LTD]![SUBPROJECTDESCRIPTION]" _
  122.         & ", [LTD]![ActivityDESCR]" _
  123.         & ", [LTD]![PROJECT_TO]" _
  124.         & ", [LTD]![SUBPROJECT_TO]" _
  125.         & ", [LTD]![Activity_To]" _
  126.         & ", LTD.VndrEmpName" _
  127.         & ", [LTD]![Phase] & ' - ' & [tblPhaseDescr]![Description]" _
  128.         & ", LTD.Organization" _
  129.         & ", LTD.OrgGrp" _
  130.         & ", LTD.Labor" _
  131.         & ", LTD.FiscalYear" _
  132.         & ", LTD.AccountingPeriod" _
  133.         & ", LTD.ACTIVITYID"
  134.  
  135.     sHaving = " HAVING (((LTD.OrgGrp) ALike """ & stOrg & """) AND ((LTD.FiscalYear)=" & DblYr & ") AND ((LTD.AccountingPeriod)<=" & DblMn & ")" _
  136.                     & " AND ((LTD.ACTIVITYID) ALike '" & stAct & "') AND ((Sum(LTD.Expenditures))<>0)) " _
  137.                 & " OR (((LTD.OrgGrp) ALike """ & stOrg & """) AND ((LTD.FiscalYear)<" & DblYr & ") AND ((LTD.ACTIVITYID) ALike '" & stAct & "') AND ((Sum(LTD.Expenditures))<>0))"
  138.  
  139.     sOrder = " ORDER BY Sum(IIf([LTD]![FiscalYear]= " & DblYr & " And [LTD]![AccountingPeriod]= " & DblMn & ",[LTD]![EXPENDITURES],0))" _
  140.         & ", Sum(IIf([LTD]![FiscalYear]= " & DblYr & " And [LTD]![AccountingPeriod]<= " & DblMn & ",[LTD]![EXPENDITURES],0))"
  141.  
  142.     ' Open recordset
  143.     Set rst = New ADODB.Recordset
  144.     sSQL = sSelect & vbCrLf & sFrom & vbCrLf & sGroupBy & vbCrLf & sHaving & ";"
  145. '    Debug.Print sSQL
  146.     rst.Open sSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
  147.     If rst.BOF And rst.EOF Then
  148.         MsgBox "No Data Available to Export", vbOKOnly, "No Data"
  149.         DoCmd.Hourglass False
  150.         Exit Sub
  151.     End If
  152.     rst.MoveLast
  153.  
  154. '    Debug.Print rst.RecordCount
  155.     iRow = rst.RecordCount + 1
  156.  
  157.     ' Create an instance of Excel and add a workbook
  158.     Set xlApp = New Excel.Application
  159.     Set xlWb = xlApp.Workbooks.Add
  160.     Set xlWs = xlWb.Worksheets("Sheet1")
  161.  
  162.     ' Display Excel and give user control of Excel's lifetime
  163.     xlApp.Visible = True
  164.     xlApp.UserControl = True
  165.  
  166.     ' Copy field names to the first row of the worksheet
  167.     fldCount = rst.Fields.Count
  168.     For iCol = 1 To fldCount
  169.         xlWs.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name
  170.     Next
  171.  
  172.     rst.MoveFirst
  173.  
  174.     ' Copy the recordset to the worksheet, starting in cell A2
  175.     xlWs.Range("A2", "XFD" & iRow).CopyFromRecordset rst
  176.  
  177.     ' Auto-fit the column widths and row heights
  178.     xlApp.Selection.CurrentRegion.Columns.AutoFit
  179.     xlApp.Selection.CurrentRegion.Rows.AutoFit
  180.     xlWs.Range("N2", "P" & iRow).NumberFormat = "$#,###;($#,###)[Red];-;-" 'Format the Amounts
  181.     xlWs.Range("Q2", "S" & iRow).NumberFormat = "#,###;(#,###)[Red];-;-" 'Format the Hours
  182.  
  183.     ' Close ADO objects
  184.     rst.Close
  185. '    conn.Close
  186.     Set rst = Nothing
  187. '    Set conn = Nothing
  188.  
  189.     ' Release Excel references
  190.     Set xlWs = Nothing
  191.     Set xlWb = Nothing
  192.  
  193.     Set xlApp = Nothing
  194.     DoCmd.Hourglass False
  195.  
  196. Exit_cmd_XprtXls_Click:
  197.     Exit Sub
  198. Err_cmd_XprtXls_Click:
  199.     DoCmd.Hourglass False
  200.     If Err.Number = 6 Then
  201.         MsgBox "The dataset you have choosen to export is too large.  Use additional filters to limit the dataset. "
  202.     Else
  203.         MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
  204.         DoCmd.SetWarnings True
  205.         DoCmd.Hourglass False
  206.     End If
  207.         Resume Exit_cmd_XprtXls_Click
  208. End Sub
Thank you for looking at this.
Jul 28 '15 #1

✓ answered by Rabbit

The range of an integer in VBA is -32,768 to 32,767.
https://msdn.microsoft.com/en-us/lib...(v=VS.60).aspx

2 3356
Rabbit
12,516 Expert Mod 8TB
The range of an integer in VBA is -32,768 to 32,767.
https://msdn.microsoft.com/en-us/lib...(v=VS.60).aspx
Jul 28 '15 #2
Thank you! That makes sense.
Jul 28 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Serge Myrand | last post by:
Hi, I have an ADODB.RecordSet that RecordCount alway return -1 and this RecordSet is plenty of record! R.RecordSet = -1 R.eof = False R.BOF = False Is the cursor is lost somewhere?
3
by: C. Sengstock | last post by:
Hi, i´ve got an iteration with random generated floating point numbers. During the iteration process sometimes the programm stops with the error: "floating point error: overflow" Is the...
3
by: Simon Jefferies | last post by:
Hello, I've created a fresh VB.NET Setup project using the wizard. When I build the project I get the following error message: ERROR: An error occurred while validating. HRESULT = '80004002'...
0
by: krakesh11 | last post by:
Hi , In my sas program , I am facing a problem of overflow error in one of my SAS programs . Kindly help me in gettingresolve this issue . The exact error message which I got is : "ERROR:...
1
pureenhanoi
by: pureenhanoi | last post by:
I'm using VB6 and MSAcces DataBase my project have one Conection called: GPcnxn, a Recordset called: GPrs. If i connect to database by DataEnvironment, so, after this command Set...
3
rsmccli
by: rsmccli | last post by:
Access 2002 Hi. I have a command button that will "approve" all records currently being looked at by an "approver". For some reason, even though there are multiple records that exist in the...
2
by: FutureShock | last post by:
I am using a registration class to process a registration form and need some opinions on returning error messages. I am self referring the page on submit. I would like to send each form field...
7
by: MaryAboyade | last post by:
i wrote this code. and kt is returning 0 even though there are records in the the recordset. rsRGLV.Filter = "matno='" & MT & "'" kt = rsRGLV.RecordCount What else can i use to get the number of...
18
by: time2hike | last post by:
Big Picture: I am trying to open 2 recordsets and test the results against a set of rules prior to loading data into my database. I have created this as a Sub attached to a command button on a form...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.