Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Pivot table not refreshing

I've created some code to change the database used in a PivotCache. (Based
on snippets found in this group.) Based on the MsgBox statement at the end,
it appears the database is changing, however a refresh of the table shows
the old data. Where am I going wrong? I'm finding it difficult to locate
good examples of changing SQL database.

Sub ChangeDatabase()
'Declare our variables.
Dim ptc As PivotCache, oldDB As String, newDB As String
Set ptc = ActiveCell.PivotTable.PivotCache

MsgBox "Connection: " & ptc.Connection ' Confirms the current settings

'Request the name of the old server/file name.
oldDB = InputBox("Input the name of the old database or file path as
listed in the Pivot Tables SQL string.")

'Request the name of the new server/file name.
newDB = InputBox("Input the name of the new database or file path which
you want the Pivot Table to point to.")

'Replace the ODBC information of whatever PivotTable is currently
active.

ptc.Connection = Application.Substitute(ptc.Connection, oldDB, newDB)
ptc.Refresh

MsgBox "Connection: " & ptc.Connection ' Shows new connection
information

End Sub


Thanks - John


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Pivot table not refreshing

Sorry about the typos in previous message. It appears my spell checker was
"improving" my English. - John

"John Michl" wrote in message
...
I believed I figured out the problem but have not solved it. Though I was
change the source of the data, I was not change the SQL statement which
still referred to the original database. When trying to change that
statement, I learned that I can't since when I set up this workbook, I
copied one pivot table and pasted as others then changed some of the

fields.
Does anyone know how to change the SELECT statement in the SQL query under
these circumstances? Thanks - John

"John Michl" wrote in message
...
I've created some code to change the database used in a PivotCache.

(Based
on snippets found in this group.) Based on the MsgBox statement at the

end,
it appears the database is changing, however a refresh of the table

shows
the old data. Where am I going wrong? I'm finding it difficult to

locate
good examples of changing SQL database.

Sub ChangeDatabase()
'Declare our variables.
Dim ptc As PivotCache, oldDB As String, newDB As String
Set ptc = ActiveCell.PivotTable.PivotCache

MsgBox "Connection: " & ptc.Connection ' Confirms the current

settings

'Request the name of the old server/file name.
oldDB = InputBox("Input the name of the old database or file path as
listed in the Pivot Tables SQL string.")

'Request the name of the new server/file name.
newDB = InputBox("Input the name of the new database or file path

which
you want the Pivot Table to point to.")

'Replace the ODBC information of whatever PivotTable is currently
active.

ptc.Connection = Application.Substitute(ptc.Connection, oldDB,

newDB)
ptc.Refresh

MsgBox "Connection: " & ptc.Connection ' Shows new connection
information

End Sub


Thanks - John






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
Refreshing a pivot table Neville Bailey[_2_] Excel Discussion (Misc queries) 1 November 16th 08 05:47 PM
Pivot Table Refreshing Yuanhang Excel Discussion (Misc queries) 0 November 30th 07 10:43 PM
Pivot table refreshing Daniel Excel Discussion (Misc queries) 5 July 12th 07 05:02 PM
When refreshing pivot tables my pivot table chart type changes hannah220507 Excel Discussion (Misc queries) 1 May 22nd 07 02:57 PM
Refreshing a pivot table Louise Excel Discussion (Misc queries) 2 May 23rd 05 01:40 PM


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