PC Review


Reply
Thread Tools Rate Thread

CopyFromRecordset with Filtered ADO recordset

 
 
Sheldon Penner
Guest
Posts: n/a
 
      8th Oct 2008
My Excel application contains the following code to enter data from an ADO
recordset, rsStats, onto an Excel spreadsheet:

rsStats.Filter = "[DIST_CODE]='" & strTerr & "'"
RecCount = rsStats.RecordCount
..Cells(n, startCol).CopyFromRecordset rsStats

This code is contained within a loop that assigns different values to
strTerr and n. The result is that it returns the various filtered recordsets
at different locations on the spreadsheet.

This works fine in VBA, but now I have to transfer this functionality into a
vbscript that uses Office Automation to instantiate the Excel application,
open the Excel file and insert the data. When the code is run from vbscript,
rsStats.RecordCount returns the correct number of records for each filtering
of the recordset, but CopyFromRecordset always prints the complete,
unfiltered recordset.

Is there some way I can get CopyFromRecordset to recognize the filter when
working through Office Automation?
 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      9th Oct 2008
I can't think of any reason why this wouldn't work the same in vbscript as
it does in VBA, as long as you didn't miss something in the translation.
Have you defined all ADO/XL intrinsic constants or replaced them with their
values ?

Tim

"Sheldon Penner" <(E-Mail Removed)> wrote in message
news:A7E7E223-6F40-4C89-A9D9-(E-Mail Removed)...
> My Excel application contains the following code to enter data from an ADO
> recordset, rsStats, onto an Excel spreadsheet:
>
> rsStats.Filter = "[DIST_CODE]='" & strTerr & "'"
> RecCount = rsStats.RecordCount
> .Cells(n, startCol).CopyFromRecordset rsStats
>
> This code is contained within a loop that assigns different values to
> strTerr and n. The result is that it returns the various filtered
> recordsets
> at different locations on the spreadsheet.
>
> This works fine in VBA, but now I have to transfer this functionality into
> a
> vbscript that uses Office Automation to instantiate the Excel application,
> open the Excel file and insert the data. When the code is run from
> vbscript,
> rsStats.RecordCount returns the correct number of records for each
> filtering
> of the recordset, but CopyFromRecordset always prints the complete,
> unfiltered recordset.
>
> Is there some way I can get CopyFromRecordset to recognize the filter when
> working through Office Automation?



 
Reply With Quote
 
Sheldon Penner
Guest
Posts: n/a
 
      9th Oct 2008
I did replace all constants with their values.

The issue has become academic in this instance. I was unaware of the
existence of the Subtotal method, so my code had been copying filtered
portions of the recordset, then adding a subtotals row beneath it, then
copying the next filtered portion, and so on. As soon as I learned of the
Subtotal method, I rewrote my code to simply copy the entire sorted recordset
onto the spreadsheet, then apply the method to add subtotals and a grand
total row. Simple!

Which leaves the question of CopyFromRecordset and filtered recordsets
unanswered. It does appear to me that Excel deals differently with it from
internal vba modules than from external vbscript.

"Tim Williams" wrote:

> I can't think of any reason why this wouldn't work the same in vbscript as
> it does in VBA, as long as you didn't miss something in the translation.
> Have you defined all ADO/XL intrinsic constants or replaced them with their
> values ?
>
> Tim
>
> "Sheldon Penner" <(E-Mail Removed)> wrote in message
> news:A7E7E223-6F40-4C89-A9D9-(E-Mail Removed)...
> > My Excel application contains the following code to enter data from an ADO
> > recordset, rsStats, onto an Excel spreadsheet:
> >
> > rsStats.Filter = "[DIST_CODE]='" & strTerr & "'"
> > RecCount = rsStats.RecordCount
> > .Cells(n, startCol).CopyFromRecordset rsStats
> >
> > This code is contained within a loop that assigns different values to
> > strTerr and n. The result is that it returns the various filtered
> > recordsets
> > at different locations on the spreadsheet.
> >
> > This works fine in VBA, but now I have to transfer this functionality into
> > a
> > vbscript that uses Office Automation to instantiate the Excel application,
> > open the Excel file and insert the data. When the code is run from
> > vbscript,
> > rsStats.RecordCount returns the correct number of records for each
> > filtering
> > of the recordset, but CopyFromRecordset always prints the complete,
> > unfiltered recordset.
> >
> > Is there some way I can get CopyFromRecordset to recognize the filter when
> > working through Office Automation?

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying recordset multiple times using copyfromrecordset JasonC Microsoft Excel Programming 5 4th Feb 2010 04:41 PM
set unbound listbox recordset to sorted and filtered ADO recordset Toxalot Microsoft Access 0 11th May 2008 09:15 AM
Excel copyfromrecordset fails with large DAO recordset MacDermott Microsoft Access VBA Modules 0 20th Sep 2007 09:48 PM
How To Append Record To Recordset from another Filtered Recordset James Microsoft Access 0 4th Aug 2006 07:45 PM
CopyFromRecordset will fail if the recordset array data such as hierarchical recordsets ??? Mike Microsoft Excel Programming 0 10th Jun 2006 03:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:09 PM.