Age field in form (1 Viewer)

DarkChild

New member
Local time
Today, 16:18
Joined
Aug 30, 2019
Messages
2
I’ve the date of birth in my form but I want to have the age automatically calculated to appear alongside in my form. I created a query that calculates the age, but trying to get that to appear in my actual form is proving difficult. I connected it to my query as a label but it just displays ?NAME in the box. Can anyone provide a solution? Its been a while since I used Access so I’m re-teaching myself. Cheers. R
 

Dreamweaver

Well-known member
Local time
Today, 16:18
Joined
Nov 28, 2005
Messages
2,466
Just Added that to my employee example version 5
https://www.access-programmers.co.uk/forums/showthread.php?t=306487


 

Attachments

  • 2019-08-26 (4).jpg
    2019-08-26 (4).jpg
    102.2 KB · Views: 183

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:18
Joined
May 7, 2009
Messages
19,230
re-create your query and add the calculated Age column:

select *, DateDiff("yyyy", [dateField], Date) As Age from tableName;

use the query as the Recordsource of your table.
add the Age column to your form.
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:18
Joined
Sep 21, 2011
Messages
14,262
Hi all. Sorry. The coding still doesn’t work ;(

You could at least show us what you have already? within quote tags please, # on the edit window bar.

I don't believe arnelgp's code will work, as it does not take month or day into consideration?
 

isladogs

MVP / VIP
Local time
Today, 16:18
Joined
Jan 14, 2017
Messages
18,213
I don't believe arnelgp's code will work, as it does not take month or day into consideration?

To be precise, it is correct provided they've already had their birthday this year.
For someone born on 31st December, the age will be 1 year too large for every date until 30 December!

There are many sites with better calculations. For example https://www.fontstuff.com/access/acctut05.htm has arnel's code and a more accurate version. Even that's not perfect due to the leap year correction for three centuries out of four.
A different method is given at exhttp://www.fmsinc.com/MicrosoftAccess/modules/examples/AgeCalculation.asp which also takes into account month and day of birth as well as year.
 

Users who are viewing this thread

Top Bottom