# access query

Hi,
I have two field in the access table: PO_No, Entry_Date.
I only like to list PO_No when Entry_Date is Older than 7 years from the Entry Date.
So based on sample records below, I like list any POs that is older than or equal to 3/26/2007.
How do I crate a query to do that?

Thanks.

PO_No                        Entry_Date
340306201      3/21/2007
0212061039      3/21/2007
340306241      3/21/2007
020207072      3/22/2007
020207073      3/22/2007
021206987      3/22/2007
021106916      3/23/2007
021106917      3/23/2007
020107033      3/24/2007
020107014      3/24/2007
490207126      3/26/2007
020107051      3/26/2007
011206976      3/26/2007
020107011      3/26/2007
020107050      3/26/2007  <---------- List this and above or older
020207081      3/27/2007
340306225      3/27/2007
020107008      3/27/2007
020207080      3/27/2007
###### Who is Participating?

Commented:
Something like this?

``````SELECT Table1.[PO_No], Table1.[Entry_Date]
FROM Table1
``````
0

CIOCommented:
You will need a proper function calculating age like the one below.
Then:

SELECT
[PO_No],
[Entry_Date]
FROM
Table1
WHERE
AgeSimple([Entry_Date]) >= 7;

``````Public Function AgeSimple( _
ByVal datDateOfBirth As Date) _
As Integer

' Returns the difference in full years from datDateOfBirth to current date.
'
' Calculates correctly for:
'   leap years
'   dates of 29. February
'   date/time values with embedded time values
'
' DateAdd() is used for check for month end of February as it correctly
' returns Feb. 28. when adding a count of years to dates of Feb. 29.
' when the resulting year is a common year.
' After an idea of Markus G. Fischer.
'
' 2007-06-26. Cactus Data ApS, CPH.

Dim datToday  As Date
Dim intAge    As Integer
Dim intYears  As Integer

datToday = Date
' Find difference in calendar years.
intYears = DateDiff("yyyy", datDateOfBirth, datToday)
If intYears > 0 Then
' Decrease by 1 if current date is earlier than birthday of current year
' using DateDiff to ignore a time portion of datDateOfBirth.
intAge = intYears - Abs(DateDiff("d", datToday, DateAdd("yyyy", intYears, datDateOfBirth)) > 0)
End If

AgeSimple = intAge

End Function
``````
/gustav
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.