Solved

Long wait query in Excel VBA

Posted on 2015-01-09
3
180 Views
Last Modified: 2015-01-26
I have a long wait query in Excel VBA :

  Rs.Open stSQL, conn, adOpenKeyset, adLockReadOnly  (take 20 - 25mins)

Current, whole Excel may be grey out or white screen. Is it possible to improve give some progress for the result of the SQL connection status such that user will not abnormally end the VBA application,.. Tks
0
Comment
Question by:AXISHK
  • 2
3 Comments
 
LVL 18

Assisted Solution

by:SimonAdept
SimonAdept earned 500 total points
ID: 40542133
There are a number of possible reasons. You don't specify what your stSQL query string is, but it could be complex, returning millions of records. Performance will obviously also depend on the data source that you're connecting to. Is it a Microsft SQL Server or something else?

How long is the wait if you use a query that returns just one row from a single table?

Is a keyset type recordset necessary? If you are not updating the records, consider the default adOpenForwardOnly.

I'd suggest you refer to the ADO recordset.open documentation on MSDN, and experiment with the command and execute options.

If possible, check how long it takes to run the same query from another client (e.g. paste the SQL statement into the MS Access query builder) or use the Excel connection wizard to create your database connection and use your SQL statement in the properties tab. If the data source is an RDBMS and you have access to its management tools (e.g. SSMS), try the query directly from there. That also has the benefit of showing you the execution plan. You may be able to optimise your query or add indexes to dramatically improve performance.

Other useful sources for you to look at would be:
ADO performance best practices on Technet
SQLMag - VB Toolkit - Tweaking ADO for Performance
0
 

Author Comment

by:AXISHK
ID: 40543648
The query really take 20 min to complete, testing on the SQL Server Query window.

Just looking for a way to increase interaction on the Excel VBA, say the progress of the TSQL query for example, Tks
0
 
LVL 18

Accepted Solution

by:
SimonAdept earned 500 total points
ID: 40543820
Sorry, I mis-read your question.

I'd suggest you look at How To Use the ADO FetchProgress and FetchComplete Events on Microsoft Support, possibly in conjunction with a progress bars, possibly in conjunction with AlainByrden's VBA progress bar article.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
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.

747 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

12 Experts available now in Live!

Get 1:1 Help Now