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.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
No. standard behavior is for the row or column field data to display in the pivot table when they are added, even if there are no values fields selected.
 
Upvote 0
Are you sure?

I confirmed that what you describe is standard in Excel 2003 (the only version I use). I used the code from post #3 of http://www.mrexcel.com/forum/excel-questions/315768-creating-pivot-table-multiple-sheets.html I set up a worksheet with headers & data, copied to give a second worksheet and ran the code. (There were only two worksheets in the file. I mention that cause the code was specifically written to make a pivot table from all worksheets. Also it has a connection string specific to Excel 2003, btw.)

What version are you using? Why do you think that what you're seeing is non-standard?
 
Upvote 0
I am using Excel 2010. If I create a pivot table using the standard UI (not from code) and use data from the same workbook or connect to an external database, this problem does not occur.
 
Upvote 0
I wouldn't call it standard. I would say the same quirk exists in 2003. Using an ADO recordset (at least with the code we both used) creates a pivot table that does not behave in the same manner as creating it any other way. I have also confirmed that creating the pivot table from code using a connecton string instead of an ADO recordset does not cause the problem. It only happens when using the ADO method. I am hoping that someone has found a workaround for this issue.
 
Upvote 0
Sounds like you have a workaround - modify to a method that gives the result you want.

This thread might disappear in the mass of postings pretty quickly, so if you're still after input from others suggest you wait some time - say til next week - and ask the question afresh. Include a link here for info. When the thread is unanswered it will be more prominent.

regards
 
Upvote 0
Unfortunately, I have to use ADO since my query uses parameters. I will repost next week. Thanks for the tip.

Regards.
 
Upvote 0
Keep ADO! (I'm a big fan of ADO :)) Load the recordset (headers &) data to a worksheet and make the pivot table from that - so it will be different from making the pivot table from the recordset. Could be a temporary, or hidden, worksheet and delete when done; or re-use with new data for each pivot table; or whatever. Or a temporary file.
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,702
Members
449,331
Latest member
smckenzie2016

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