?
Solved

How do you create and store a SELECT query in VBA, QUERYDEF does not seem to apply to select query definitions

Posted on 2007-12-06
6
Medium Priority
?
797 Views
Last Modified: 2013-11-27
I have a complex query that uses other queries which should run off user-supplied dates. I want to create the base queries using a date paramter and store them - then use them in the comples query joins.

Access does not appear to allow you to store a SELECT query using the QUERYDEF statement.

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
  • 3
6 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 20420880
This sounds like way too much work.

What is the requirement for creating these queries via VBA code, and not pre-creating them manually?
0
 

Author Comment

by:fester62
ID: 20420927
I tried doing that originally but the queries run off a data parameter. I can specify a parameter in the query designer but then that pops up a box when the query runs - whereas i want the query to use txtRunDate supplied on a Form. - I am not sure how to get the query to work off that date and not prompt the user, without using code.

your help is appreciated.

tony
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 20420963
>whereas i want the query to use txtRunDate supplied on a Form.
In that case, just feed that value in your query. (Below is air code, rename the obvious)  

{SQL View}
SELECT blah, blah, blah
FROM blah
WHERE SomeDate = [Forms]![SomeFormName]![SomeTextboxName]

{Design View}
In the column that has the date you want to compare to your form field, enter this in the criteria row
[Forms]![SomeFormName]![SomeTextboxName]

0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

Author Comment

by:fester62
ID: 20421497
Ok, I can see how that should work, actually instead of a textbox i want it to pick up a DTpicker1.value, but when I susbitute that into your suggested code ti does not work (for either a textbox or a DTpicker), do i need to enclose with '#' or some other formatting ? Cant get that to work either.

tony
0
 

Author Comment

by:fester62
ID: 20421533
ok, I have it working off a textbox now, just had the date in the wrong format. Now I need to get it working with a dtpicker control. Should there be a difference, cant see why ?

tony
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 20422426
>do i need to enclose with '#' or some other formatting ?
If the SQL is pieced together by VBA, yes, otherwise no.  
Just to be safe though, in case the form control value is being read into the query as text, use CDate... CDate([Forms]![SomeFormName]![SomeTextboxName])

This also assumes that the form is open, and the value in SomeTextboxName is in date format.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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 …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

770 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