CopyFromRecordset vs Ado.recordset filter

J

JCP

I created a recordset and now I need to use recordset filter to export data
into excel.

I use the CopyFromRecordset method to export data into excel
When I use this method using the recordset filter, it ignores the filter and
CopyFromRecordset export to all records to excel.

There is an away to export data to excel from a ado.recordset filter?

Dim cnn as ADODB.connection
Dim rs as ADODB.recordset
Dim rs1 as ADODB.recordset

' Code to open a specifive excel file ...

Set cnn= CurrentProject.Connection
Set rs= New ADODB.recordset
rs.Open strSQL, cnn 'This recordset has 62 rows;
rs.filter="Source='Bagre'" 'This recordset has 7 records

xlBook.Sheets(1).Range("D10").CopyFromRecordset rs

'The line above copy all data from the recordset, I mean, copy into excel
62 records and not 7. It ignore the filter

also I tried:

Dim cnn as ADODB.connection
Dim rs as ADODB.recordset
Dim rs1 as ADODB.recordset

‘Code to open a specifive excel file ...

Set cnn= CurrentProject.Connection
Set rs= New ADODB.recordset
rs.Open strSQL, cnn 'This recordset has 62 rows;
rs.filter="Source='Bagre'" 'This recordset has 7 records
set rs1=rs

xlBook.Sheets(1).Range("D10").CopyFromRecordset rs1

'The results is the same, export all records into excel.

How can I export only the records filtered?

Thanks for any suggestions.

jcp
 
J

JCP

Thanks Jamie,

I'm using ms excel 2003.
I couldn't understand how can use getrows. Could you givem a simple example?

However, I don't understand why recordset filet doesn't work.

jcp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top