Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem with date range in a query criteria

Posted on 2014-03-17
7
Medium Priority
?
481 Views
Last Modified: 2014-03-20
I'm using this in query designer and not getting the correct result:

Between [Forms]![frmSelectLocationAndDatesForProductSalesReport]![txtStart] And [Forms]![frmSelectLocationAndDatesForProductSalesReport]![txtEnd]

So I'm wondering if my syntax is incorrect.

Is there a better way to capture data between two dates?  Or?

--Steve
0
Comment
Question by:SteveL13
7 Comments
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39934358
Hi,
try to convert your string Dates in dates first before comparing them

DateValue([MyField])

Open in new window

Regards
0
 

Author Comment

by:SteveL13
ID: 39934371
Where and how do I do that?
0
 
LVL 7

Accepted Solution

by:
COACHMAN99 earned 2000 total points
ID: 39934538
Between DateValue([Forms]![frmSelectLocationAndDatesForProductSalesReport]![txtStart] ) And DateValue([Forms]![frmSelectLocationAndDatesForProductSalesReport]![txtEnd])
0
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.

 

Author Comment

by:SteveL13
ID: 39934603
Ok.  This is working.  But why?
0
 
LVL 40

Expert Comment

by:PatHartman
ID: 39934775
The dates in your table include time and so that is interfering with the criteria.  The DateValue() function strips out just the date part of the field.  If you really don't want to store time as well as date, change your default and/or code to use Date() rather than Now().  Then write an update query using the DateValue() function to replace all the values with only the date.

To allow for dates to contain time and not use the DateValue function, you have to add a day to the end date.

YourDate >= FromDate and < EndDate +1

The problem is with the EndDate
YourDate = 1/1/2014 11:35:33 AM
FromDate = 1/1/2014
EndDate = 1/1/2014

The time parts of the From and End dates are 00:00:00 AM
So YourDate is >= FromDate
but
YourDate is NOT <= EndDate because of the time.  The time part makes it > the EndDate.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 39934802
It's rather that

    [Forms]![frmSelectLocationAndDatesForProductSalesReport]![txtStart]

returns a string value while

    DateValue([Forms]![frmSelectLocationAndDatesForProductSalesReport]![txtStart])

returns a (you guessed it) a date value.

/gustav
0
 
LVL 40

Expert Comment

by:PatHartman
ID: 39935015
Referencing the control only returns a string if the control is unbound and  therefore not defined as a date/time data type.

The DateValue() solves the problem of stripping time out of a date/time field so you can do your compare using only the date part of the value.  If you want just the time part, you would use TimeValue().  Remember, dates are stored as double precision numbers.  DateValue() returns the integer and TimeValue() returns the decimal.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

885 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