473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Query Filter Question

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
May 4 '19 #1
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:
Expand|Select|Wrap|Line Numbers
  1.  DateAdd("YYYY",70,JP_tbl.[DOB]) AS Expr1
Also DATEDIFF(..) will give you the age of a person:
Expand|Select|Wrap|Line Numbers
  1. DateDiff("yyyy",JP_tbl.DOB, Now()) AS Age
May 4 '19 #2
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:

Expand|Select|Wrap|Line Numbers
  1. Function Age(varDOB As Variant, Optional varAsOf As Variant) As Variant
  2.     'Purpose:   Return the Age in years.
  3.     'Arguments: varDOB = Date Of Birth
  4.     '           varAsOf = the date to calculate the age at, or today if missing.
  5.     'Return:    Whole number of years.
  6.     Dim dtDOB As Date
  7.     Dim dtAsOf As Date
  8.     Dim dtBDay As Date  'Birthday in the year of calculation.
  9.  
  10.     Age = Null          'Initialize to Null
  11.  
  12.     'Validate parameters
  13.     If IsDate(varDOB) Then
  14.         dtDOB = varDOB
  15.  
  16.         If Not IsDate(varAsOf) Then  'Date to calculate age from.
  17.             dtAsOf = Date
  18.         Else
  19.             dtAsOf = varAsOf
  20.         End If
  21.  
  22.         If dtAsOf >= dtDOB Then      'Calculate only if it's after person was born.
  23.             dtBDay = DateSerial(Year(dtAsOf), Month(dtDOB), Day(dtDOB))
  24.             Age = DateDiff("yyyy", dtDOB, dtAsOf) + (dtBDay > dtAsOf)
  25.         End If
  26.     End If
  27. End Function
]
May 4 '19 #3
Luuk
1,047 Expert 1GB
@zmbd: Thanks for details on how to calculatie age more precise..
May 4 '19 #4
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 :
Expand|Select|Wrap|Line Numbers
  1. (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().
May 4 '19 #5
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)
May 5 '19 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
8
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...
7
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...
1
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...
2
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...
1
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...
5
dsatino
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...
6
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...
3
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...
12
Seth Schrock
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...
0
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...
0
isladogs
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...
0
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,...
0
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$) { } ...
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.