LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Changing SQL Statement for PivotCache linked to multiple tables

Tom, thanks for the response but I can't seem to change the database and SQL
string when the pivottable cache is "shared" among several tables. The code
below will NOT work when I use on a table that has a shared pivotcache.
However, it WILL work on a table that does not share a cache. Any ideas?

Sub ChangeDatabase()
Dim ptc As PivotCache, OldDB As String, NewDB As String
Set ptc = ActiveCell.PivotTable.PivotCache

'Request the name of the old and new database name.
OldDB = InputBox("Input the name of the old database as listed in
the Pivot Tables SQL string.")
NewDB = InputBox("Input the name of the new database.")

ptc.Connection = Application.Substitute(ptc.Connection, OldDB,
NewDB)

' ERROR AT NEXT LINE Run-time Error '1004'
Application-defined or object-defined error

ptc.Sql = Application.Substitute(ptc.Sql, OldDB, NewDB)
ptc.Refresh

End Sub

"Tom Ogilvy" wrote in message
...
Same as you would for a pivotcache used by a single table.

The pivot Table settings determine what is shown, but what is available to
be shown is the same for all the tables tied to that single cache. Think

of
the cache as an intermediate data table with some extra meta data.

Regards,
Tom Ogilvy

"John Michl" wrote in message
...
Thanks, Tom.

Are you aware of a way to change the SQL statement for a pivot cache

that
used by more than one table?

- John

"Tom Ogilvy" wrote in message
...
PivotTables do not use other pivottables as the data source under the
scenario you describe. What they do is use the original pivotcache as

the
same datasource.

Dim pCache as PivotCache
set pCache = ActiveSheet.PivotTables(1).PivotCache

will give you a reference to the pivot cache.

Regards,
Tom Ogilvy


"John Michl" wrote in message
...
I've stumbled along with some VBA programming that allows me to

change
the
connection and sql properties of a pivot cache. Unfortunately, I've
learned
that it is difficult (or perhaps impossible) to change the SQL

statement
for
a pivotcache that is linked to more than one pivot table. In my

workbook,
I
have a dozen or so pivottables most of which were created by either
copying
the first table or creating a new table that used the first table as

the
data source.

1) Does anyone know of a work around that would allow me to change

the
SQL
properties of these linked tables? (I've got the code working fine

for
a
single table but not tables based on one central source.)

2) Is there away to determine which table is the initial table from

which
the others are derived? When I look at the connection properties

they
all
seem to look like they connect to the SQL database not to a pivot

table.

Thanks.



P.S. I've left a number of messages regarding similar topics over

the
past
week with no response. Sorry for being a pest but I'm in a world of

hurt.

- John










 
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
Changing Data Source on Multiple Pivot Tables at once marjhan Excel Worksheet Functions 1 October 23rd 08 09:03 AM
Can I add an item to a PivotCache with VBA? John Brock Excel Discussion (Misc queries) 4 June 16th 08 01:00 PM
subtotals in linked tables dave oatley Excel Worksheet Functions 0 November 21st 07 08:55 PM
Remove specific Pivotcache fields Dan Bayliss Excel Discussion (Misc queries) 0 September 13th 06 03:32 AM
Changing PivotCache SQL Database John Michl[_2_] Excel Programming 0 July 15th 03 09:45 PM


All times are GMT +1. The time now is 07:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"