Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

compiling queries

Posted on 2013-01-29
15
Medium Priority
?
234 Views
Last Modified: 2013-01-30
I noticed when starting from a blank database and importing in many queries from an older database the forms are terribly slow when opening. I think I found the reason but still need a little help. It seems since the queries have never been opened the have never been compiled. If I open them, show the data, then close, the forms seems to open faster.

If this is the case is there a way to open and close or compile all the queries in vb?
0
Comment
Question by:Shawn
[X]
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
  • 5
  • 5
  • 4
  • +1
15 Comments
 
LVL 75
ID: 38832822
"If I open them, show the data, then close, the forms seems to open faster."

That is because the JET query execution plan is recreated based on current datasets. So, effectively - you have 'recompiled' the queries.

"If this is the case is there a way to open and close or compile all the queries in vb?"
I'm thinking if in vba, you open each QueryDef and then save/close ... this may do the same thing.

mx
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38832833
the first time the query executes, the query will be compiled, then the compiled query is used when the query is executed.
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 1336 total points
ID: 38832847
That is correct.  This occurs after a compact and repair as well.

What's happening is that the plan for query execution is being generated and saved.

I don't have code off-hand to open and execute every query, but for the most part, you could do it in VBA.

However it would depend on the queries and how they were writen as to how easy or complete it would be.

 What you would need to do would depend on the type  (action, select, pass-through), what they are doing (ie. tied to a form), and if they must be done in sequence (ie. make table, then appends after that).

Jim.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75
ID: 38832848
Maybe something like this (make a backup first).  I just tried this - but I have no way to tell on this system if it makes a difference.

    Dim qdf As dao.QueryDef
    Dim db As dao.Database
    Set db = CurrentDb
    For Each qdf In db.QueryDefs
         Debug.Print qdf.Name
         On Error Resume Next  ' in case query has systax error, like some of my EE qrys.
        qdf.sql = qdf.sql
        Err.Clear
        qdf.Close
    Next qdf
   
    Set qdf = Nothing
    Set db = Nothing
0
 
LVL 58
ID: 38832852
<<I'm thinking if in vba, you open each QueryDef and then save/close ... this may do the same thing.>>

 Has to be a open of the query def, modification of the SQL, a save, and then a execute of the query without a save after that to force a re-compile.

Jim.
0
 
LVL 75
ID: 38832941
"a save"
So how do you actually 'save' in vba ?  Say relative to the code I posted.
0
 
LVL 58
ID: 38833092
There's no code equivalent.   Just setting the property seems to be enough, although it may be when it goes out of scope or is closed that the save actually takes place.  I've never really pinned it down.

 When I answered though, I was thinking of the steps I'd do manually, so I really didn't answer that correctly.

 A execution is required though, which is where doing this in code becomes a problem depending on how the queries are written.

Jim.
0
 
LVL 75
ID: 38833118
Execute - yeah, that's what I suspected - and yes, problematic in code most likely.

The good news: Compact & Repair.

mx
0
 
LVL 1

Author Comment

by:Shawn
ID: 38833151
does Compact & Repair really compile the queries though?
0
 
LVL 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 1336 total points
ID: 38835162
<<does Compact & Repair really compile the queries though?>>

  It doesn't compile them.  What it does is flag them as not compiled, so first time they are run, they are re-compiled.

 That's one of the reasons I've never bothered with trying to compile all queries before I deliver something...it's just not worth the effort.

Jim.
0
 
LVL 1

Author Comment

by:Shawn
ID: 38835886
>>so first time they are run, they are re-compiled.
even when theyare behind a form or do they still have to be run/opened directly?
0
 
LVL 58
ID: 38835926
<<even when theyare behind a form or do they still have to be run/opened directly? >>

 That was my point earlier; many won't run outside of a certain situation, such as a form being opened.

Jim.
0
 
LVL 1

Author Comment

by:Shawn
ID: 38835936
ok, thanks Jim. You just saved me a lot of time. :-)

Shawn
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 664 total points
ID: 38836425
"even when theyare behind a form "
I believe they are still flagged for recompile (after a C&R) since they do appear in the QueryDef collection - show as (example):

~sq_ffrmLstBox

Thing is ... since C&R only flags queries for recompile ... this may be why - you experience slowness - at various times - when a given query is actual recompiled upon first use after a C&R.  However, how today's machines this may be so fast that is't negligible - probably hard to measure/determine.

mx
0
 
LVL 1

Author Closing Comment

by:Shawn
ID: 38837234
thanks for helpin g me understand. So solution is we don't need vb but a C&R. C&R sure comes in handy.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 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