Solved

Problem with date range in a query criteria

Posted on 2014-03-17
7
470 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
[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
7 Comments
 
LVL 52

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

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

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 51

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 38

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

617 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