Is it possible to clone a pivotcache recordset?

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,907
Office Version
  1. 365
Platform
  1. Windows
Hi

Does anyone know how to create a new recordset as an exact copy of an existing pivot cache recordset? I can't access the external data that the pivot table is created from. I would like to either create a new recordset that is an exact copy, or output the entire existing recordset to a text file. I have tried the following:

Code:
[COLOR=blue]Public[/COLOR] [COLOR=blue]Sub[/COLOR] CloneRecordSet()
    [COLOR=blue]Dim[/COLOR] recData [COLOR=blue]As[/COLOR] ADODB.Recordset
    [COLOR=blue]Dim[/COLOR] pvc [COLOR=blue]As[/COLOR] PivotCache
 
    [COLOR=blue]Set[/COLOR] pvc = Sheet4.PivotTables(1).PivotCache
    [COLOR=blue]Set[/COLOR] recData = pvc.Recordset.Clone(adLockUnspecified) [COLOR=red]'error on this line[/COLOR]
 
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
Application-defined or object-defined error.

I have also tried:
Rich (BB code):
Set recData = pvc.Recordset
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Since the board has picked up a bit: BUMP

Put it another way:
Assume you have a pivot table that was built from an Access table. That Access table gets deleted. How do you retrieve the full table of data from the pivot table since all of it should be stored in the pivot cache. Bearing in mind that the record count exceeds the # of rows (XL03).

Any idea? :)

EDIT: I'm thinking a stepped approach by taking segments from the pivot table using ShowDetail method is possible. But I'm hoping I can simply collect the recordset somehow instead.
 
Last edited:
Upvote 0
Jon

I think the stepped approach is probably a good bet if you can't get the xml suggestion to work. I just tested it on a small pivot table and it worked pretty well.

Since this is an oldish question did you finally solve this issue?
 
Upvote 0
I liked your suggestion of getting it from the XML file. On the face of it, it seems that all my data is there. So thanks for that! :beerchug:

I haven't pulled all the data out yet because I've given my time to rebuilding the DB tables etc. I think I'll start work on the data tomorrow.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top