Solved

Where should I place QUERYDEFS so they can be accessed from a form module (they are referenced several times by form code).

Posted on 2007-12-05
5
272 Views
Last Modified: 2013-11-27
I have a form and have coded my queries using VBA. At the moment I delete them and re-create them everytime I run them as a timekey parameter may change plus the user may run the tool several times and an error would occur if QUERYDEF.CREATE method finds that the query already exists. I basically want to create the queries once in code and be able to call them with a timekey parameter at any time during the running of the programmme.

Will querdefs persist after the application closes down ? If so that would give me an error the next time the tool is opened (hence I delete and recreate everytime) and the code runs to create the queries.

 I could just set up the objects once and leave them out of the VBA code I suppose, but ideally I want the code to include every object used. Am I going about this the right way ? I havent used QUERYDEFS before so am not sure where they shouold be placed so they are created once and can theb be called several times passing in a timekey(date) parameter.

Tony
0
Comment
Question by:fester62
[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
  • 3
5 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 100 total points
ID: 20410706
The actual QWuery Def is stored as a Query in the MDB - you will see them if you open the Query Tab in the Databse View.  Yes, they persist when the Application is shut down.

If you define the Query so that the TimeKey is a parameter of the query, then yes, you can run the same query and provide a new timekey input value.

AW
0
 

Author Comment

by:fester62
ID: 20410827
Would I need code that runs immediately the application is opened that checks for the existence of the queries, if they dont exists it creates them, or would you recommend keeping the query definitions outside of VBA code and then just calling them by name with the paramter as required ? These are queries that will be re-run daily so would be classified as permanent in nature.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 20411014
Try the second choice, and see if that satifies your requirements.  That will save you some execution cycles.  But the First choice will always work - just costs a bit of performance.

AW
0
 
LVL 6

Assisted Solution

by:bknouse
bknouse earned 25 total points
ID: 20411513
Please be aware that a querydef is an object that can be manipulated.  For example, I have a pass-through query connected via ODBC to a back-end IBM DB2 database.  Instead of creating multiple instances of the same type of query, I manipulate the sql property of the querydef.  The syntax to modify the sql (where sqlZ is a string variable holding the sql statement):

CurrentDb.QueryDefs("nameOfQuery").sql = sqlZ

Brent
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 20808542
why only a B.  What additional information or assistance would you like?

Glad to be of assistance.

AW
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

710 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