From my previous question (which I greatly appreciated the answer).
I have now added a tbl named JP_tbl. It has 4 fields.
Name, (typical name ie Joe Bloggs)
DOB, (01/01/2001)
Date expiry in date format (01/01/2001)+ 70 years
Completed (True/ False) Tick Box
What I need to do is filter out the records where by the DOB (date of birth) is calculated to give a result for Date expiry plus 70 years. Once that date is reached it is removed from the qry
Also where completed true/false would further filter the results.
Sounds ominous but work has certain rules where by anyone plus 70 years can not make certain decisions for legal requirements.
Maybe via a Expr:[...... ??
Can I run this straight from the qry?
Thanks in advance
5 973 Luuk 1,047
Expert 1GB
I do think that you do not need the field 'Date expiry'. When it's always 70 years after DOB, than this expression will do it: - DateAdd("YYYY",70,JP_tbl.[DOB]) AS Expr1
Also DATEDIFF(..) will give you the age of a person: - DateDiff("yyyy",JP_tbl.DOB, Now()) AS Age
zmbd 5,501
Expert Mod 4TB
I 2nd Luuk's opinion that the expry field is unneeded IF and only if it will always be 70+ years from DOB. It's a good rule of thumb not to store information that can be calculated from the data in the table.
As for calculating the age, there are some minor issues that can arise, and I have had the following happen to me... http://allenbrowne.com/func-08.html
Age() Function
Given a person's date-of-birth, how do you calculate their age? These examples do not work reliably:
Format(Date() - DOB, "yyyy")
DateDiff("y", DOB, Date)
Int(DateDiff("d", DOB, Date)/365.25)
DateDiff("y", ..., ...) merely subtracts the year parts of the dates, without reference to the month or day. This means we need to subtract one if the person has not has their birthday this year. The following expression returns True if the person has not had their birthday this year:
DateSerial(Year(Date), Month(DOB), Day(DOB)) > Date
True equates to -1, so by adding this expression, Access subtracts one if the birthday hasn't occurred.
The function is therefore: - Function Age(varDOB As Variant, Optional varAsOf As Variant) As Variant
-
'Purpose: Return the Age in years.
-
'Arguments: varDOB = Date Of Birth
-
' varAsOf = the date to calculate the age at, or today if missing.
-
'Return: Whole number of years.
-
Dim dtDOB As Date
-
Dim dtAsOf As Date
-
Dim dtBDay As Date 'Birthday in the year of calculation.
-
-
Age = Null 'Initialize to Null
-
-
'Validate parameters
-
If IsDate(varDOB) Then
-
dtDOB = varDOB
-
-
If Not IsDate(varAsOf) Then 'Date to calculate age from.
-
dtAsOf = Date
-
Else
-
dtAsOf = varAsOf
-
End If
-
-
If dtAsOf >= dtDOB Then 'Calculate only if it's after person was born.
-
dtBDay = DateSerial(Year(dtAsOf), Month(dtDOB), Day(dtDOB))
-
Age = DateDiff("yyyy", dtDOB, dtAsOf) + (dtBDay > dtAsOf)
-
End If
-
End If
-
End Function
]
Luuk 1,047
Expert 1GB
@zmbd: Thanks for details on how to calculatie age more precise..
NeoPa 32,556
Expert Mod 16PB
If you're actually interested in whether or not someone has reached their 70th birthday than calculating their age would be irrelevant and just give you extra troubles.
The part of the WHERE clause that would exclude records where the subject is >=70 would be : - (Date()>=DateAdd('yyyy',70,[DOB]))
This assumes you are checking it against today's date. If other dates are required then specify that in place of Date() .
WOW!! Such great and quick help, very much appreciated. Hadn't even thought about not needing a expiry field and just using above but makes total sense and now slapping myself as to why I thought I needed it in the first place.
Greatly appreciated for everyones help on this! Ill give it a crack when I get back to work tomorrow (Don't have Access at home)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: inna |
last post by:
Hello. I have query performance question.
I need to optimize procedure
CREATE PROCEDURE dbo.SECUQUSRCOMPACCES
@P1 VARCHAR(50),
@P2 INTEGER
AS
DECLARE @IORGANIZATIONID INTEGER
EXECUTE...
|
by: Együd Csaba |
last post by:
Hi All,
how can I improve the query performance in the following situation:
I have a big (4.5+ million rows) table. One query takes approx. 9 sec to
finish resulting ~10000 rows. But if I run...
|
by: Mike |
last post by:
I'm trying to filter a dataset on items that are being passed in via a
querystring.
the string looks like this.
chevy|ford|BMW|
on the information page i split the string such as...
|
by: Regnab |
last post by:
I've got a form where the user can edit the lookups available in the
database. It consists of a list box of the various categories on the
main form, a checkbox on the main form and a sub form which...
|
by: sharsy |
last post by:
Hello,
I have a Database setup that has two tables that are linked. Table1
contains a list of people with their basic contact details (name &
phone number etc.) and Table2 contains a list of all...
|
by: jaad |
last post by:
I am setting up a multi-users database. The login procedure creates a temporary variable called! which I use throughout the database to filter data the user sees only the data that relates to his or...
|
by: dsatino |
last post by:
I have an Access query whose results are filtered by a custom VBA function. This works perfectly as long as the function returns a result. If the function doesn't return a result, neither does the...
|
by: Ryan Sandlin |
last post by:
Hello,
I recently created a module in Access based on the code I found here:
http://www.utteraccess.com/forum/fNetWorkdays-fAddWorkDay-t1349593.html&hl=workdays
The code basically created 2...
|
by: Coolbreeze |
last post by:
Hi,
I have specified form textbox data as query filter criteria,and since then, every time I run the query, the criteria are self duplicating on random lines below the original. Also, there seems to...
|
by: Seth Schrock |
last post by:
I have a very complex query that I use as the record source for a report. I want it to run all its calculations as little as possible. My question is, is there a difference between putting a WHERE...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |