Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Querytable and pivot table refresh problem

HI all,

I have a external data query, which is refreshed by the user via a button on
the sheet.
on a different sheet is the pivot table if the data which datasource is the
excel sheet that has the query. Pretty normal stuff
In the code linked to a button on the sheet I refresh the data from the
mssql server. Once that is done I refresh the pivot table. However the pivot
table is not refreshed, it would still contain the old data.
I have seen that by adding a msgbox before the pivot refresh that the new
data is not updated in the spreedseat until the sub is finned and exited.
Which makes perfect sens as to why the pivot table is not being refreshed
with the new data, because at the time the refresh code is run, nothing is
returned via the query to exccel.

How can I achieve this programatically. I want to to have one sub, to
refresh the excel query from MSSQL, and when that is done, refresh the pivot
table

The code used is

Sub RefreshAllData()
Application.DisplayAlerts = False
If Len(Login.tbUsername.Text) = 0 Or Len(Login.tbPassword.Text) = 0 Then
Login.Show
End If
sPassword = Login.tbPassword.Text
sUser = Login.tbUsername.Text
Excel.Application.ScreenUpdating = True
Updating.ProgressBar1.Value = 0
Updating.Repaint
Updating.Show (Modal)
Application.PivotTableSelection = True

If Login.btnCancel.cancel = False Then
If Len(sPassword) = 0 Or Len(sUser) = 0 Then
Conn = ""
MsgBox ("No Login info")
Else
Set wbA = ActiveWorkbook
sPassword = Login.tbPassword.Text
sUser = Login.tbUsername.Text
Updating.ProgressBar1.Max = wbA.Worksheets.Count + 1
Updating.ProgressBar1.Value = 1
Updating.Repaint
For Each ws In wbA.Worksheets
For Each qt In ws.QueryTables
Conn = "ODBC;DRIVER=SQL Server;SERVER=192.168.1.197;UID=" +
sUser + ";PWD=" + sPassword + ";APP=Microsoft Office
2003;WSID=GABRIEL;DATABASE=WOWDynamicList"
qt.Connection = Conn
Application.StatusBar = "Refreshing Data from server " &
qt.Name
qt.Refresh
Login.Repaint
Updating.ProgressBar1.Value = Updating.ProgressBar1.Value + 1
Updating.Repaint
Next

Next
End If
End If
Updating.Hide
updatepivot
Application.DisplayAlerts = True
Application.StatusBar = False
End Sub


Sub updatepivot()
Set wbA = ActiveWorkbook
For Each ws In wbA.Worksheets
''ws.Activate
For Each pvtTable In ws.PivotTables
Application.DisplayAlerts = False
Application.StatusBar = "Updating PivotTable " & pvtTable.Name
pvtTable.RefreshTable


Next
Next
Application.DisplayAlerts = True
Application.StatusBar = False
End Sub


Thanks
Robert


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
Pivot table refresh problem mindyg Excel Worksheet Functions 2 March 14th 09 01:43 PM
Pivot Table Refresh Problem Robert Hamilton Excel Worksheet Functions 2 May 9th 06 08:10 PM
Pivot table Refresh problem seantera Excel Discussion (Misc queries) 0 January 24th 06 06:52 PM
PIVOT TABLE REFRESH PROBLEM Ian Digby[_3_] Excel Programming 0 June 21st 04 09:57 AM
pivot table grid formatting problem after refresh annie Excel Programming 0 April 1st 04 09:41 PM


All times are GMT +1. The time now is 10:18 AM.

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"