Solved

Date range criteria

Posted on 2014-10-28
2
256 Views
Last Modified: 2014-10-28
I want to query data based on a form.  The form has a single date field named txtEndDate.

But in the query criteria I have:

Between [Forms]![frmDate]![txtEndDate]-365 And [Forms]![frmDate]![txtEndDate]

which I'm sure isn't the right way to do it especially if it was a leap year.  I want to end up querying from a year ago through the date entered on the form.

How should my criteria read?

--Steve
0
Comment
Question by:SteveL13
  • 2
2 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
Comment Utility
I would suggest

Between DateAdd("yyyy",-1,[Forms]![frmDate]![txtEndDate]) And [Forms]![frmDate]![txtEndDate]
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
Comment Utility
Just bear in mind - today is Oct 28. If someone types in Oct 28, 2014, and you have something with a date and time of Oct 28, 2014 12:00, then it won't be caught by "Oct 28, 2014", because Access will assume that it is midnight of that day.

Therefore, you may want

>=DateAdd("yyyy",-1,[Forms]![frmDate]![txtEndDate]) And <[Forms]![frmDate]![txtEndDate]+1

or

>=DateAdd("yyyy",-1,[Start]) And <DateAdd("d",1,[Start])

if that is a possibility.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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.

772 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

15 Experts available now in Live!

Get 1:1 Help Now