Solved

query table in excel not refreshing

Posted on 2014-11-17
5
136 Views
Last Modified: 2014-12-06
I have an excel workbook that is connected to an access query that imports the access data into one of my worksheets as a table. I have a vba script that auto opens this worbook, and tells it to refresh all contents including the query table and the other worksheets that have formulas dependent in the query table. When i run the speeadsheet manually, the query imports perfectly. But when the spreadsheet is auto run from the task manager, the query table doesnt update fast enough before the rest of the vba code proceeds and closes the worbook.  I tried disabling background refresh in the excel data connection options, and tried adding some code in vba sucha as DoEvents, application.refreshall, etc but still doesnt help.

Can someone provide some vba code that calls the query object and then validate that the refresh is completed for that specific query? Lets say my workbook is called worbook1.xlsm, the query table is called query1table, and query1table is located on sheet2.  I see this is a common problem, but i havent found a solution yet.
0
Comment
Question by:jtencha
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Michael74
ID: 40448976
Try

Application.CalculateUntilAsyncQueriesDone

after calling the refresh command

http://msdn.microsoft.com/en-us/library/office/ff821008(v=office.15).aspx
0
 

Author Comment

by:jtencha
ID: 40451222
Thanks. I tried that also, didnt help. Is there querytable property that can be verified that refresh is complete, and continhe reading the rest of my code? Btw, the code is auto launched from a private sub from  'this worbook' module.
0
 
LVL 23

Accepted Solution

by:
Michael74 earned 500 total points
ID: 40451272
Is this what you are after

QueryTable.Refreshing Property
http://msdn.microsoft.com/en-us/library/office/ff834459(v=office.15).aspx
0
 

Author Comment

by:jtencha
ID: 40453022
ok, will try that, will let you know how it goes
0
 

Author Closing Comment

by:jtencha
ID: 40485049
thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question