Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default MS Query becomes inert

Excel 2003, Windows XP

I have a query embedded in a worksheet. If I select a cell within the
query, I am able to refresh the data without any problems. However, normally
I use the following macro to refresh the queries in the workbook, since other
non-technical users also use this file. Most of the time, this works without
any problems.

Sub Auto_Open()

Dim ws As Worksheet
Dim qt As QueryTable
Dim pt As PivotTable
Dim Answer As Variant
Dim RunMe As Variant

'Double check that the user wants to retrieve new data from Movex.
RunMe = MsgBox("Do you want to get updated data from Movex", vbYesNo +
vbQuestion, "Movex Update")
If RunMe = vbNo Then Exit Sub


'Turn off screen updating and calculation to save time
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'Cycle through all worksheets and refresh all querytables
For Each ws In ThisWorkbook.Worksheets
For Each qt In ws.QueryTables
qt.Refresh False
Next qt
Next ws

'after downloads complete, recalculate all formulas copied by the MS query
download
Application.CalculateFull

'Cycle through and refresh all pivot tables
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
Next pt
Next ws

'Set calculation back to automatic
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

'Notify that everything is finished
Answer = MsgBox("Download complete", vbOKOnly, "Movex ODBC Download")

End Sub

However, sometimes the macro fails at the statement 'qt.Refresh False'
After this happens, I go back and find that the query is no longer a query.
I know this because the External Data Toolbar buttons become grayed out. If
I go into INSERT-NAMES-DEFINE, I can see that the query name now has spaces
in it.

Before running the macro, it looks like this =Sheet1!$A$1:$E$415
When the macro fails, if I go back in it will look like = Sheet1!$A$1:$E$415
(notice the spaces after the equal sign)

Does anyone have any guesses what the problem is?

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
Convert hard coded query criteria to Parameter Query Melanie[_2_] Excel Discussion (Misc queries) 0 July 15th 08 09:59 PM
Excel 2007 / MS Query - editing existing query to another sheet Hotpepperz Excel Discussion (Misc queries) 0 June 13th 08 06:53 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 1 November 29th 05 01:44 PM
How to make first Row inert? wavetoall Excel Discussion (Misc queries) 2 November 8th 05 09:03 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


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