Solved

Access 2007 Date Query Criteria -6 by date

Posted on 2014-09-10
7
510 Views
Last Modified: 2014-09-10
I need help with a query on one of my tables. On one of the table fields there is a date mm/dd/yyyy. I need to have the user input a future date and then count back 6 years from the table field date. I only want to see the dates that fall in the 6 year window.

 ex: user input - 06/01/2015

 the query would pull only the dates starting 06/01/2009 to 05/31/2010
0
Comment
Question by:CMILLER
  • 4
  • 2
7 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 40315923
Use something like
WHERE DATE BETWEEN DATEADD("yyyy",-6, Date Passed) and DatePassed
0
 

Author Comment

by:CMILLER
ID: 40315927
Thats not working
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 40315932
select [datefield]
from tablex
where [datefield] between dateadd("yyyy',-6,[enter Date]) And  dateSerial(Year([Enter Date]) - 5, Month([Enter Date]), 0)
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

Author Comment

by:CMILLER
ID: 40315936
I am getting a "The expression you entered has an invalid string" A string can be up to 2048 char long, including opening and closing quotation marks
0
 

Author Comment

by:CMILLER
ID: 40315946
found it

("yyyy'
0
 

Author Comment

by:CMILLER
ID: 40315959
is my thinking correct on this?

If I am going back 6 yrs from a date ( 06/15/2015 ) would that be in between 6/01/2009 to 5/31/2010?

or is it between 5/31/2008 to 6/01/2009?
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 40315966
Not sure  - open the immediate window of VBA and type in the expression as ?Datevalue(with your details) and see what it returns.


Kelvin
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

948 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

20 Experts available now in Live!

Get 1:1 Help Now