PC Review


Reply
Thread Tools Rate Thread

Changing PivotTable Source programmatically

 
 
Roberto Villa Real
Guest
Posts: n/a
 
      29th Oct 2009
I have several pivot tables in a workbook that get data from an Access .mdb
file.

But sometimes I need these pivot tables to obtain data from another Access
file.

Can I programmatically change the Source File of a Pivot Table, without
changing its query? Shall I use the PivotTableWizard? Or is there any
property that contains the Source File path?

 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      30th Oct 2009
do you read the data using ADO ? If so, then the answer is easy - yes.

when you read the data into a recordset, all you need to do is set the pivot
cache's recordset property to this recordset and refresh the piviot table
To changethe source, all you need is alter the connection string.

do you need a code example?

Sub LoadDataFromAccess()
Dim MyFile As String
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String
Dim i As Long

MyFile = "Risk.mdb"

SQL = "SELECT * FROM BondTable"

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyFile

rst.Open SQL, con, adOpenStatic

Cells.Clear
'headers
For i = 0 To rst.Fields.Count - 1
Cells(1, i + 1).Value = rst.Fields(i).Name
Next
' data
Range("A2").CopyFromRecordset rs

rst.Close
con.Close

Set rst = Nothing
Set con = Nothing

End Sub





"Roberto Villa Real" wrote:

> I have several pivot tables in a workbook that get data from an Access .mdb
> file.
>
> But sometimes I need these pivot tables to obtain data from another Access
> file.
>
> Can I programmatically change the Source File of a Pivot Table, without
> changing its query? Shall I use the PivotTableWizard? Or is there any
> property that contains the Source File path?
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically changing a Data Source's connection property RB0135 Microsoft VB .NET 2 25th Jul 2007 05:58 PM
Re: Programmatically getting a Max value from a PivotTable Bernie Deitrick Microsoft Excel Programming 0 25th Oct 2006 02:32 PM
I NEED TO KNOW THE SOURCE OF A PIVOTTABLE FROM ACCESS =?Utf-8?B?Rk9STVVMQQ==?= Microsoft Excel Misc 0 20th Jul 2006 05:27 PM
Programmatically reading data field values from PivotTable =?Utf-8?B?RW5yaWNvIENhbXBpZG9nbGlv?= Microsoft Excel Programming 2 13th Jul 2005 12:32 PM
Changing PivotTable source atakacs Microsoft Excel Programming 3 7th Nov 2003 03:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:09 AM.