Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default CopyFromRecordset Ignores Filters

Help!!

I'm trying to paste ADO recordset data into an excel spreadsheet from VB6.
The syntax I'm using is:
Range.CopyFromRecordset MyAdoRecordset
where Range is a single Excel cell, and MyAdoRecordset is, well, an ADO
recordset.

This normally works perfectly. However, if the recordset is filtered, the
filter is ignored. For example, the recordset has 20 records. I apply a
filter to the recordset. When I query the AbsolutePosition & RecordCount
properties in the immediate window, I get 1 and 3 (depending on filter)
respectively, as expected. So far so good. When I execute the
CopyFromRecordset method, the spreadsheet contains all 20 rows. Very curious.

Does anybody know why this happens, and how to prevent it?

--
Ron Mittelman
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default CopyFromRecordset Ignores Filters

Ron,

I was about to say this doesn't happen to me then I went back and checked
some of my code. There's a problem in Excel 97 with the CFR method. See
below for a workaround depending on version:

Sub OutputRecordset(rsName As ADODB.Recordset, Optional lstartpos As Long)
' Author : Robin Hammond
' Purpose : dumps a recordset to a new workbook
'---------------------------------------------------------------------------------------

Dim W As Workbook
Dim nField As Integer
Dim lRowPos As Long
Set W = ActiveWorkbook
Workbooks.Add
With rsName
For nField = 1 To .Fields.Count
Cells(1, nField).Value = .Fields(nField - 1).Name
Next nField
If .RecordCount = 0 Then Exit Sub
.MoveFirst
If Not IsEmpty(lstartpos) Then .Move lstartpos
End With
'n.b. error with cfr in excel 97
If Val(Application.Version) < 9 Then
With rsName
.MoveFirst
lRowPos = 2
Do While Not .EOF
For nField = 1 To .Fields.Count
Cells(lRowPos, nField).Value = rsName(nField - 1).Value
Next nField
.MoveNext
lRowPos = lRowPos + 1
Loop
End With
Else
#If VBA6 Then
Cells(2, 1).CopyFromRecordset rsName
#End If
End If
On Error GoTo 0
End Sub

Robin Hammond
www.enhanceddatasystems.com

"Ron Mittelman" wrote in message
...
Help!!

I'm trying to paste ADO recordset data into an excel spreadsheet from VB6.
The syntax I'm using is:
Range.CopyFromRecordset MyAdoRecordset
where Range is a single Excel cell, and MyAdoRecordset is, well, an ADO
recordset.

This normally works perfectly. However, if the recordset is filtered, the
filter is ignored. For example, the recordset has 20 records. I apply a
filter to the recordset. When I query the AbsolutePosition & RecordCount
properties in the immediate window, I get 1 and 3 (depending on filter)
respectively, as expected. So far so good. When I execute the
CopyFromRecordset method, the spreadsheet contains all 20 rows. Very
curious.

Does anybody know why this happens, and how to prevent it?

--
Ron Mittelman



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table filters, especially DATE filters chris Excel Worksheet Functions 0 August 27th 08 04:33 AM
Filters, Subtotal & Intacted Results after the filters' Removal kasiopi Excel Discussion (Misc queries) 5 February 24th 06 12:18 PM
CopyFromRecordset does nothing Hafeez Excel Programming 2 August 13th 04 07:20 PM
CopyFromRecordset does nothing E Harris Excel Programming 5 January 8th 04 04:29 PM
Copyfromrecordset Bug ? news.btx.dtag.de Excel Programming 1 August 1st 03 07:44 PM


All times are GMT +1. The time now is 01:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"