Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tod tod is offline
external usenet poster
 
Posts: 114
Default Streamline PivotTable creation code

I have some tried and true code that creates a pivot table
using ADO to get data from an Access database. I use this
code in all workbooks that have pivot table reports. Works
great. So what I'm doing now is looking where I can reduce
the amount of code and take out unneeded lines, etc.

I have this one section:

sql = "Select * From qryName"
cn.Open "Driver={Microsoft Access Driver
(*.mdb)};Dbq=C:\Database Folder\Database Name.mdb;"
rs.Open sql, cn

Set PC = ThisWorkbook.PivotCaches.Add
(SourceType:=xlExternal)
Set PC.Recordset = rs
Set PT = PTSheet.PivotTables.Add(PivotCache:=PC,
TableDestination:=SheetName.Range("A9"))
With PT
'...... work with the pivot table

This connects to the database, runs my query and creates
the results in a recordset. Then it creates a pivotcache
and puts the recordset in the pivotcache. Then it creates
the pivottable from the pivotcache.

Could I eliminate a step and just have the pivotcache
create from the connection, or is this about the best way
to do it.

Suggestions?

tod




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Streamline PivotTable creation code

If you have a query in Access that creates your recordset, or you can do it
with an sql statement, then I believe you should be able to create the pivot
cache directly from the table. Easiest way would be to do it manually with
the recorder on to see the code. But I am sure you can create it without
going through ADO (which wasn't an option in xl97 I am pretty sure).
--
Regards,
Tom Ogilvy

"Tod" wrote in message
...
I have some tried and true code that creates a pivot table
using ADO to get data from an Access database. I use this
code in all workbooks that have pivot table reports. Works
great. So what I'm doing now is looking where I can reduce
the amount of code and take out unneeded lines, etc.

I have this one section:

sql = "Select * From qryName"
cn.Open "Driver={Microsoft Access Driver
(*.mdb)};Dbq=C:\Database Folder\Database Name.mdb;"
rs.Open sql, cn

Set PC = ThisWorkbook.PivotCaches.Add
(SourceType:=xlExternal)
Set PC.Recordset = rs
Set PT = PTSheet.PivotTables.Add(PivotCache:=PC,
TableDestination:=SheetName.Range("A9"))
With PT
'...... work with the pivot table

This connects to the database, runs my query and creates
the results in a recordset. Then it creates a pivotcache
and puts the recordset in the pivotcache. Then it creates
the pivottable from the pivotcache.

Could I eliminate a step and just have the pivotcache
create from the connection, or is this about the best way
to do it.

Suggestions?

tod






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
Pivottable code problem Ruben Excel Discussion (Misc queries) 4 August 28th 08 03:31 PM
big list. Need advice for a new user of how to streamline it Kent New Users to Excel 2 April 1st 08 09:23 PM
How to streamline this Formula? Kuda Excel Discussion (Misc queries) 1 February 7th 06 03:05 PM
streamline SUMPRODUCT gpie Excel Worksheet Functions 4 September 23rd 05 06:05 PM
code for creation of multiple pivot tables John C[_5_] Excel Programming 1 November 19th 03 02:20 AM


All times are GMT +1. The time now is 08:54 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"