?
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
?
798 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

650 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