Pivot table created from ADO recordset doesn't display Row or Column field data unless there is a Datafield

gmars

New Member
Joined
Feb 14, 2013
Messages
6
I have created a pivot table from an ADO recordset using VBA. The pivot table is created and everything seems normal. However when I start adding row or column fields, the title cells display in the sheet, but not the individual records. They records will not appear until I add a datafield to the Values area, then everything works properly. if you remove the datafield, all data in the table, except the titles, disappears. Any help would be greatly appreciated. Below is the code that assigns the recordset to the pivot cache.

Set pvtCache = ActiveWorkbook.PivotCaches.Add(xlExternal)
Set pvtCache.Recordset = myRecordSet
Set pvtTable = pvtCache.CreatePivotTable(ActiveSheet.Range("c3"), "Exhibit")

Thanks.
 
Solved! Turns out you were on the right track. The ADO code I was using creates a pivot table as xlPivotTableVersion2000. The other methods create it as xlPivotTableVersion14. To solve the problem you have to create both the pivot cache and the pivot table as version 14. This also requires changing the pivot cache create line from an "Add" to a "Create". The adjusted lines are below:


Set pvtCache = ActiveWorkbook.PivotCaches.Create(xlExternal, , xlPivotTableVersion14)
Set pvtCache.Recordset = myRecordSet
pvtCache.CreatePivotTable TableDestination:="TestSheet!R3C3", TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion14
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,217,365
Messages
6,136,123
Members
449,993
Latest member
Sphere2215

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