+ Reply to Thread
Results 1 to 2 of 2

CopyFromRecordset does not copy sorted recordset why?

  1. #1
    Registered User
    Join Date
    04-28-2005
    Posts
    1

    CopyFromRecordset does not copy sorted recordset why?

    Hi,

    I have created an adodb.Recordset in my VB app displayed in a datagrid, sorted it into descending order and then I want to export thesorted records into Excel. I have tried using CopyFromRecordset but the data in Excel is displayed unsorted...

    the Recordset is very large and majority of time will exceed the Rows available in Excel (65536) but so long as I can get the first 65536 records from the sorted Recordset I don't mind about losing the rest...

    how do I do this?
    I am not linked to any database...
    I just have the recordset object...
    copying record by record takes far too long

    any ideas would be very much appreciated

    thanks in Advance

    Kay

  2. #2
    Registered User
    Join Date
    09-09-2009
    Location
    wr45
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: CopyFromRecordset does not copy sorted recordset why?

    Dim rs2 As DAO.Recordset 'used for sorting
    Set rs = dbs.OpenRecordset("someTable", dbOpenDynaset)
    rs.Sort = "Type ASC" 'where Type is a fieldname part of the "someTable"
    Set rs2 = rs.OpenRecordset
    excl.ActiveSheet.Cells(2, 1).CopyFromRecordset rs2
    'reset the sort since the sort property is still used if you open other recordsets using rs 'variable
    rs.sort=0

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1