Solved

Access 2007 Date Query Criteria -6 by date

Posted on 2014-09-10
7
517 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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
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.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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 retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

831 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