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
274 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

623 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