Solved

Problem with date range in a query criteria

Posted on 2014-03-17
7
460 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 49

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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

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

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 35

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

777 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