Solved

query table in excel not refreshing

Posted on 2014-11-17
5
129 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now