Results 1 to 5 of 5
  1. #1
    jgelpi16 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    CopyFromRecordset not exporting all rows from Access to Excel

    Hello,
    I'm using the below code to attempt to export data from Access to an Excel template (Access & Excel 2010). The export works fine with one exception: Only the first ~150-200 records export when I'm expecting to export over 1,000. Any ideas what I'm doing wrong? I have had others in my office look at it and we just can't seem to figure it out.



    Code:
        
        Dim db1                      As DAO.Database    
        Dim rs1                      As DAO.Recordset
        
        Dim mySQL1                   As String
        Dim strSheet1                As String
        Dim strFolder1               As String
        Dim strFolderCopy1           As String
        Dim strFileTemp1             As String
        Dim strFile1                 As String
        Dim strRange1                As String
        
        Dim xlApp                   As Object
        Dim xlSheet                 As Object
        Dim fso1                     As New FileSystemObject
        
        Dim ExcelRunning            As Boolean
        
        Set db1 = CurrentDb
        
        ExcelRunning = IsExcelRunning()
        
        If ExcelRunning Then
            Set xlApp = GetObject(, "Excel.Application")
            ExcelRunning = True
        Else
            Set xlApp = CreateObject("Excel.Application")
            ExcelRunning = False
        End If
        
        mySQL1 = "SELECT * from QRY_SEL_SCORECARD_DATA_EXPORT_RGN;"
        Set rs1 = db1.OpenRecordset(mySQL1, dbOpenDynaset)
        rs1.MoveLast
        rs1.MoveFirst
        
        strSheet1 = "PerfData"
        strFolder1 = "\\Ncmain\users\COMMON_HR\#HRIS\Reports\Performance_Scorecard\Backend_Data\"
        strFolderCopy1 = "\\Ncmain\users\COMMON_HR\#HRIS\Reports\Performance_Scorecard\Scorecard_Export\"
        strFileTemp1 = "PerformanceScorecard_TEMPLATE.xlsx"
        strFile1 = "PerformanceScorecard_Region_" & strReg & "_" & Format(Date, "yyyymmdd") & ".xlsx"
        'strFile = "PerformanceScorecard_" & Format(Date, "yyyymmdd") & ".xlsx"
        strRange1 = "B4:Y4"
        
        fso1.CopyFile strFolder1 & strFileTemp1, strFolderCopy1 & strFile1, True
        
    '    Set objMyWorkbook = objApp.Workbooks.Open(strFolder & strFile)
        Set xlSheet = xlApp.Workbooks.Open(strFolderCopy1 & strFile1)
        xlSheet.Sheets(strSheet1).Range(strRange1).CopyFromRecordset rs1
        rs1.Close
        
        With xlApp.Application
            .ActiveWorkbook.Save
            .ActiveWorkbook.Close
        End With
        
        If Not ExcelRunning Then
            xlApp.Quit
        End If

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Just a note :
    Set rs1 = db1.OpenRecordset(mySQL1, dbOpenDynaset)
    rs1.MoveLast
    rs1.MoveFirst
    THE
    rs1.MoveLast
    rs1.MoveFirst
    is not needed.


    BUT.. you have a limiter I think...strRange1 = "B4:Y4"
    Just put it in 1 cell like:

    ActiveWorkbook.Worksheets("Sheet1").Range("B4").Co pyFromRecordset


    Let the recordset decide how many cells it wants to use.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Cannot replicate the issue, even with range limit. Would have to examine and test with your data.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    jgelpi16 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Hmmmm....Is there any limitation/timeout that you all are aware of when it comes to DAO export using CopyFromRecordset? My source data is simply a query that is limited by Region (returning roughly 1,200 in my test scenario). As you can see I'm not doing anything special with the data. I'm even stopping before I get to the formatting of the template.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Not that I am aware of. I had no problem exporting 960 (unfiltered) records.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-13-2013, 12:00 PM
  2. Exporting more than 65000 Access rows to Excel
    By TonyBender in forum Import/Export Data
    Replies: 8
    Last Post: 08-22-2013, 04:56 PM
  3. Replies: 3
    Last Post: 03-12-2013, 11:34 AM
  4. Replies: 10
    Last Post: 12-28-2012, 02:06 PM
  5. exporting data from access to excel
    By tariq nawaz in forum Access
    Replies: 3
    Last Post: 09-06-2012, 09:29 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums