Solved

Long wait query in Excel VBA

Posted on 2015-01-09
3
186 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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