Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Long wait query in Excel VBA

Posted on 2015-01-09
3
188 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:Simon
Simon 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:
Simon 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

861 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