473,473 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do you calculate someones age?

I'm creating an MS Access 2000 database where I have a number of people
entered using simple basic fields, Surname: SMITH
Forenames: John
DoB: 09/09/1958
Age: (this needs to be automated to show years e.g. 46)

I am trying to get the age to be automatically shown after a persons DoB
(date of birth) is entered into the DoB field. I have tried using this
formula in the Control Source of the Age field =DAYS360([DoB],Now()) and
setting the format to yy, but am getting totally confused. Can anyone help
me (I know very little Visual Basic and hoping to get arounfd this problem
using some functiomn of formala to calculate the age)

Jan

Nov 13 '05 #1
4 9316
Look back at recent posts in the newsgroup, someone asked this same question
recently.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Jan Szymczuk" <sz******@btinternet.com> wrote in message
news:cq**********@sparta.btinternet.com...
I'm creating an MS Access 2000 database where I have a number of people
entered using simple basic fields, Surname: SMITH
Forenames: John
DoB: 09/09/1958
Age: (this needs to be automated to show years e.g. 46)

I am trying to get the age to be automatically shown after a persons DoB
(date of birth) is entered into the DoB field. I have tried using this
formula in the Control Source of the Age field =DAYS360([DoB],Now()) and
setting the format to yy, but am getting totally confused. Can anyone help
me (I know very little Visual Basic and hoping to get arounfd this problem
using some functiomn of formala to calculate the age)

Jan


Nov 13 '05 #2
=DateDiff("yyyy", Date(), [DoB]) - _
IIf(Format(Date(), "mmdd") < Format([DoB], "mmdd", 1, 0)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Jan Szymczuk" <sz******@btinternet.com> wrote in message
news:cq**********@sparta.btinternet.com...
I'm creating an MS Access 2000 database where I have a number of people
entered using simple basic fields, Surname: SMITH
Forenames: John
DoB: 09/09/1958
Age: (this needs to be automated to show years e.g. 46)

I am trying to get the age to be automatically shown after a persons DoB
(date of birth) is entered into the DoB field. I have tried using this
formula in the Control Source of the Age field =DAYS360([DoB],Now()) and
setting the format to yy, but am getting totally confused. Can anyone help
me (I know very little Visual Basic and hoping to get arounfd this problem
using some functiomn of formala to calculate the age)

Jan


Nov 13 '05 #3
Hi Jan:

At http://members.iinet.net.au/~allenbrowne/func-08.html, you will find the
following function by Allen Browne:

'-----------------------------------------------------------------------------
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
'-----------------------------------------------------------------------------

I assume you have a textbox for DOB input, maybe named txtDOB and a textbox
to show Age, maybe named txtAge. In Form Design view, click on the txtDOB,
and then right-click the mouse. At the bottom of the window that opens up,
choose "Properties". When the Properties window opens up, choose the
"Event" tab. The first event in the listing is "BeforeUpdate". Click on it,
and then on the elipsis ("...")that appears. When the Choose Builder
window appears, choose "Code Builder". You will be taken to the Visual
Basic Editor, and be inside an empty subroutine for the BeforeUpdate event.
Type:

Me!txtAge = Age(Me!txtDOB)

Then, paste the Age function down below your BeforeUpdate soubroutine.

If everything works correctly, when you enter a Date of Birth and then leave
the txtDOB textbox, the person's age will appear in txtAge. Change the
textbox names if necessary to what you have. I hope it works for you.

Alan

"Jan Szymczuk" <sz******@btinternet.com> wrote in message
news:cq**********@sparta.btinternet.com...
I'm creating an MS Access 2000 database where I have a number of people
entered using simple basic fields, Surname: SMITH
Forenames: John
DoB: 09/09/1958
Age: (this needs to be automated to show years e.g. 46)

I am trying to get the age to be automatically shown after a persons DoB
(date of birth) is entered into the DoB field. I have tried using this
formula in the Control Source of the Age field =DAYS360([DoB],Now()) and
setting the format to yy, but am getting totally confused. Can anyone help
me (I know very little Visual Basic and hoping to get arounfd this problem
using some functiomn of formala to calculate the age)

Jan


Nov 13 '05 #4
Thankyou Douglas for your simple and very elegant solution, I shall forever
be in your debt.

Jan
"Jan Szymczuk" <sz******@btinternet.com> wrote in message
news:cq**********@sparta.btinternet.com...
I'm creating an MS Access 2000 database where I have a number of people
entered using simple basic fields, Surname: SMITH
Forenames: John
DoB: 09/09/1958
Age: (this needs to be automated to show years e.g. 46)

I am trying to get the age to be automatically shown after a persons DoB
(date of birth) is entered into the DoB field. I have tried using this
formula in the Control Source of the Age field =DAYS360([DoB],Now()) and
setting the format to yy, but am getting totally confused. Can anyone help
me (I know very little Visual Basic and hoping to get arounfd this problem
using some functiomn of formala to calculate the age)

Jan


Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum...
1
by: Building Blocks | last post by:
Hi, All I need is a simle calculate form script which contains this: A script that can handle text input, radio buttons, checkboxes, and dropdowns. Each one of these variables will contain a...
2
by: Gálos Zsuzsa | last post by:
Hi all, I need to calculate Formulas. For example: dim strFormula as string="25*(12-6)" I ned a DotNet Function to calculate this Formula (25*(12-6)=150): dim dblValue as double = 150
1
by: Robert de Ridder | last post by:
I use an asp page to display pages, where the dynamic content is in an iframe. To calculate the height of the iframe I use the calcheight function. However when trying to do this with external...
1
by: Ladislau S. | last post by:
Dear reader, I am an occasional user of MS Access 2000 running on Windows 98. My hobby is ship model building so I made a database for things that I want to buy. After two strokes I bin unable...
1
by: mimirocs | last post by:
I would like to get a software that can make me find someones password by putting the persons username.
3
by: Libber39 | last post by:
Hi everyone, Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now...
0
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars...
6
by: rrstudio2 | last post by:
I am using the following vba code to calculate the median of a table in MS Access: Public Function MedianOfRst(RstName As String, fldName As String) As Double 'This function will calculate the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.