Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default filtered recodset to pivot table (or not)

It rather astonishes me that this is the only reliable route I have found,
but here's a solution to this that very annoyingly creates a new
disconnected recordset and clones every single value across while the filter
is applied to the original.

I'd still be interested if anyone can think up something better.

Set rsFilteredRS = New ADODB.Recordset
rsOriginal.Filter = "filter string goes here"
Append RS rsFilteredRS, rsOriginal
'do the output

Public Sub AppendRS(rsOutput As ADODB.Recordset, _
rsInput As ADODB.Recordset)
' Procedure : AppendRS
' DateTime : 4/15/2004 12:24
' Author : Robin Hammond
' Purpose : creates a recordset if it doesn't exist and adds input values
to the output recordset

Dim nFieldCounter As Integer
'if the output rs is empty then copy across the fields
With rsOutput
If .Fields.Count = 0 Then
For nFieldCounter = 0 To rsInput.Fields.Count - 1
.Fields.Append rsInput.Fields(nFieldCounter).Name, _
rsInput.Fields(nFieldCounter).Type, _
rsInput.Fields(nFieldCounter).DefinedSize, _
(rsInput.Fields(nFieldCounter).Attributes Or _
adFldUpdatable) And Not adFldUnknownUpdatable
Next nFieldCounter
.Open CursorType:=adOpenStatic
End If
rsInput.MoveFirst
Do While Not rsInput.EOF
.AddNew
For nFieldCounter = 0 To .Fields.Count - 1
.Fields(nFieldCounter).Value =
rsInput.Fields(nFieldCounter).Value
Next nFieldCounter
rsInput.MoveNext
Loop
End With
End Sub

Robin Hammond
www.enhanceddatasystems.com


"Robin Hammond" wrote in message
...
Has anyone found a way to get a pivottable to work with a filtered
recordset?

The intent is fairly simple. Filter a complex RS, pass a column, row, and
data parameter to a generic output routine, and use a pivottable to do the
output to a worksheet. It seems that although the recordset is filtered,

the
pivottable ignores the filtering and includes all items.

I'm sure I can get around it by adding an additional column and filtering
the column, pastevalues, delete the column, etc, but would rather the damn
thing behaved as it should.

Correct:
rsWhatever.Filter = "something"
Set pcOutput.Recordset = rsWhatever

Incorrect:
probably about 50 lines of nasty code adding additional columnfield and
filtering the pivottable.
Sometimes you have to question who's thinking these things up.

There's a thread with a response from Rob Bovey here saying that it can't

be
done directly, but I'd welcome other suggestions.


http://www.google.com.hk/groups?hl=e...r%3D%26hl%3Den

Robin Hammond
www.enhanceddatasystems.com




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default filtered recodset to pivot table (or not)

"Robin Hammond" wrote ...

It rather astonishes me that this is the only reliable route I have found,
but here's a solution to this that very annoyingly creates a new
disconnected recordset and clones every single value across while the filter
is applied to the original.

I'd still be interested if anyone can think up something better.


Hi Robin,
You can save the filtered recordset to an ADO Stream and open a new
recordset based on stream. Here's some code:

http://www.able-consulting.com/ADO_Faq.htm#Q42

Jamie.

--
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default filtered recodset to pivot table (or not)

Thanks Jamie.

Blazingly simple as usual, though I'd still like to know why the filters
aren't maintained when the RS is passed to the pivot.

Robin Hammond
www.enhanceddatasystems.com


"Jamie Collins" wrote in message
om...
"Robin Hammond" wrote ...

It rather astonishes me that this is the only reliable route I have

found,
but here's a solution to this that very annoyingly creates a new
disconnected recordset and clones every single value across while the

filter
is applied to the original.

I'd still be interested if anyone can think up something better.


Hi Robin,
You can save the filtered recordset to an ADO Stream and open a new
recordset based on stream. Here's some code:

http://www.able-consulting.com/ADO_Faq.htm#Q42

Jamie.

--



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 -Show Q3 and Q4 with non-filtered Total Aldo Excel Discussion (Misc queries) 0 December 28th 09 12:45 PM
How can i get a sum of the data filtered in a pivot table tarabull Excel Discussion (Misc queries) 1 March 26th 09 02:13 PM
Can pivot table column labels be filtered? terri.hirsch Excel Discussion (Misc queries) 1 August 14th 08 04:43 PM
What is filtered in a Pivot Table? Finding out quickly... BenS Excel Discussion (Misc queries) 0 April 3rd 07 01:32 PM
Using Pivot Table to Display Filtered Data Only Dawg House Inc Excel Discussion (Misc queries) 6 February 14th 07 01:03 AM


All times are GMT +1. The time now is 03:45 AM.

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

About Us

"It's about Microsoft Excel"