Link to home
Start Free TrialLog in
Avatar of fester62
fester62Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fester62

ASKER

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.
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
why only a B.  What additional information or assistance would you like?

Glad to be of assistance.

AW