Solved

Problem with date range in a query criteria

Posted on 2014-03-17
7
452 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 48

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 500 total points
ID: 39934538
Between DateValue([Forms]![frmSelectLocationAndDatesForProductSalesReport]![txtStart] ) And DateValue([Forms]![frmSelectLocationAndDatesForProductSalesReport]![txtEnd])
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

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

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 49

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 34

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now