Solved

Problem with date range in a query criteria

Posted on 2014-03-17
7
456 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

867 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

22 Experts available now in Live!

Get 1:1 Help Now