Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default How to modify the sql statement on a pivot table using VBA- XL2000

Hi,
I need help modifying the sql statemnet for a pivot table. I create a pivot
table using ODBC connection. I created fine and even the refresh work fine.
But when I need to modify the query to add new conditions to the sql
statement, the pivot pivot still refreshes with the old slq. It does get
change.
refrsh code:

' odbc connection and sql statement would be he:

Sub RefreshPivotTables()
'This routine calls the refresh method for each sheet's pivot table
Dim sSheet As String
Application.ScreenUpdating = False
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets(sSheet)
Set ptCache = wbBook.PivotCaches(1)
Set ptTable = wsSheet.PivotTables(sSheet)
ptTable.RefreshTable
Application.ScreenUpdating = True
End Sub

Any help would be appreciated. Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to modify the sql statement on a pivot table using VBA- XL2000

I don't know if you are trying to modify the SQL in a macro or manually. You
can edit the SQL manually by going to the worksheet where the query is
located then go to menu

Data - Import external Data - Edit query.

You can find the Query Name by look at the Define Names in the Worksheet menu

Insert - Names - Define and select the query name

You can modify the SQL statment from a macro knowing the Query Name that you
get from the Define Menu above.

Set objQryTbl = Sheets("Sheet2").QueryTables("ABC") where ABC is the
Define Name

The SQL will be

MySQL = objQryTbl.commandtext




"Carlos" wrote:

Hi,
I need help modifying the sql statemnet for a pivot table. I create a pivot
table using ODBC connection. I created fine and even the refresh work fine.
But when I need to modify the query to add new conditions to the sql
statement, the pivot pivot still refreshes with the old slq. It does get
change.
refrsh code:

' odbc connection and sql statement would be he:

Sub RefreshPivotTables()
'This routine calls the refresh method for each sheet's pivot table
Dim sSheet As String
Application.ScreenUpdating = False
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets(sSheet)
Set ptCache = wbBook.PivotCaches(1)
Set ptTable = wsSheet.PivotTables(sSheet)
ptTable.RefreshTable
Application.ScreenUpdating = True
End Sub

Any help would be appreciated. Thanks.

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
XL2000 - Password to Modify Problem LPS Excel Discussion (Misc queries) 2 November 8th 08 04:38 PM
XL2000 Pivot Table - Show Pages LPS Excel Discussion (Misc queries) 2 October 29th 08 02:55 PM
XL2000: Pivot Table Limitations II LPS Excel Discussion (Misc queries) 3 October 15th 08 09:43 PM
XL2000 Pivot Table Specifications LPS Excel Discussion (Misc queries) 3 October 3rd 08 09:12 PM
Pivot Table Macro to run in XL2000 Jonathan May Excel Programming 2 June 24th 04 09:53 AM


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