Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Pivot Table Pain!

Dear All

I am trying to automate the creation of a pivot table,
whether from within Excel or through automation from
another package and always seem to get an error when
trying to load the ADO recordset data into the pivot cache
(see sample code below). If I add a pivotcache to the
pivotchaches collection I receive no error, but when I try
to Set objPivotcache.Recordset = rstRecordset then I get
an error. I am simply stumped. If the pivotcache object is
added to the pivotcaches collection, then should each
pivotcache not have an Index?

Can anyone help me?

Alastair

Sub CreatePivot()
On Error GoTo err_handler:
Dim SQLString As String
Dim cnnConn As ADODB.Connection
Dim rstRecordset As ADODB.Recordset
Dim cmdCommand As ADODB.Command
Dim objPivotcache As Excel.Pivotcache

'RECORDSET OPENED AND POULATED WITH DATA

Set objPivotcache = xlApp.ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlExternal)

'THIS LINE HERE IS WHERE THE 1004 AUTOMATION ERROR OCCURRS.

Set objPivotcache.Recordset = rstRecordset
With objPivotcache
.CreatePivotTable TableDestination:=Range("B5"), _
TableName:="pivAccessNL"
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Pivot Table Pain!

Alastair

It worked for me from within Excel. I found a few other posts on google
with the same problem, but alas, no answers. I would try it with a
different recordset (the smaller and simpler) and see if there's a problem
with the recordset (maybe size or complexity).

If you get it to work with a small, simple recordset, maybe it will help
isolate the problem. Sorry I couldn't be more help.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Alastair MacFarlane" wrote in message
...
Dear All

I am trying to automate the creation of a pivot table,
whether from within Excel or through automation from
another package and always seem to get an error when
trying to load the ADO recordset data into the pivot cache
(see sample code below). If I add a pivotcache to the
pivotchaches collection I receive no error, but when I try
to Set objPivotcache.Recordset = rstRecordset then I get
an error. I am simply stumped. If the pivotcache object is
added to the pivotcaches collection, then should each
pivotcache not have an Index?

Can anyone help me?

Alastair

Sub CreatePivot()
On Error GoTo err_handler:
Dim SQLString As String
Dim cnnConn As ADODB.Connection
Dim rstRecordset As ADODB.Recordset
Dim cmdCommand As ADODB.Command
Dim objPivotcache As Excel.Pivotcache

'RECORDSET OPENED AND POULATED WITH DATA

Set objPivotcache = xlApp.ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlExternal)

'THIS LINE HERE IS WHERE THE 1004 AUTOMATION ERROR OCCURRS.

Set objPivotcache.Recordset = rstRecordset
With objPivotcache
.CreatePivotTable TableDestination:=Range("B5"), _
TableName:="pivAccessNL"
End With



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Pivot Table Pain!

Dick Kusleika

Thanks for the comments. The problem I have is that it works sometimes and
more often errors at exactly the same point. So annoying. Programming can be
like that sometimes.

I thought that a possible problem could've been that an instance of excel
would remain in memory and somehow the caches of the two instances of Excel
could error. Unfortunately I am accessing excel on a remote pc and can't see
the instances of excel stored on the pc.

Thanks again.

Alastair

"Dick Kusleika" wrote in message
...
Alastair

It worked for me from within Excel. I found a few other posts on google
with the same problem, but alas, no answers. I would try it with a
different recordset (the smaller and simpler) and see if there's a problem
with the recordset (maybe size or complexity).

If you get it to work with a small, simple recordset, maybe it will help
isolate the problem. Sorry I couldn't be more help.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Alastair MacFarlane" wrote in

message
...
Dear All

I am trying to automate the creation of a pivot table,
whether from within Excel or through automation from
another package and always seem to get an error when
trying to load the ADO recordset data into the pivot cache
(see sample code below). If I add a pivotcache to the
pivotchaches collection I receive no error, but when I try
to Set objPivotcache.Recordset = rstRecordset then I get
an error. I am simply stumped. If the pivotcache object is
added to the pivotcaches collection, then should each
pivotcache not have an Index?

Can anyone help me?

Alastair

Sub CreatePivot()
On Error GoTo err_handler:
Dim SQLString As String
Dim cnnConn As ADODB.Connection
Dim rstRecordset As ADODB.Recordset
Dim cmdCommand As ADODB.Command
Dim objPivotcache As Excel.Pivotcache

'RECORDSET OPENED AND POULATED WITH DATA

Set objPivotcache = xlApp.ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlExternal)

'THIS LINE HERE IS WHERE THE 1004 AUTOMATION ERROR OCCURRS.

Set objPivotcache.Recordset = rstRecordset
With objPivotcache
.CreatePivotTable TableDestination:=Range("B5"), _
TableName:="pivAccessNL"
End With





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
Template Help Task Pane is being a pain! Barry Excel Discussion (Misc queries) 3 March 29th 10 08:04 PM
Task Pain tc Excel Discussion (Misc queries) 4 August 29th 07 04:44 PM
Comments on frozen pain Flints Excel Discussion (Misc queries) 2 August 8th 06 04:41 PM
Oh God the Pain! Help Please! jshpik1 Excel Discussion (Misc queries) 2 May 9th 06 08:25 AM
Is there any way to keep the Task Pane (pain) from displaying? Terrible I Excel Discussion (Misc queries) 2 February 6th 06 09:35 PM


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