Results 1 to 6 of 6
  1. #1
    raywhite is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    3

    Auto update student's age

    NEWBY. I am very new to Access and I am creating a database for a children's home we run.
    It will contain details of all the children.
    I would like to be able to have a place where I input their date of birth and another field where the database automatically tells me their age and yet another field where the database automatically tells me when they will turn 18 years old.
    Can I do this and if so how?
    naturally there will also be a lot of other fields such as name, gender, date admitted, school class etc. I think those should be fairly simple but the date / age / turns 18 on have me lost.
    Any help much appreciated
    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Calculate age in query, don't store in table. Same for the 18th birthday.

    Calculating age is not as simple as might think. Review http://access.mvps.org/access/datetime/date0001.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    raywhite is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    3
    Quote Originally Posted by June7 View Post
    Calculate age in query, don't store in table. Same for the 18th birthday.

    Calculating age is not as simple as might think. Review http://access.mvps.org/access/datetime/date0001.htm
    Thank you for your really helpful reply. No wonder it had me baffled. I feel sure that by following the info in the link you kindly provided I will manage.
    Much appreciated.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Agree with June. Using an Age function to calculate Age in a query as needed.
    There are many different Age functions, some more complex than others.
    The one I use is probably the the most concise

    Code:
    Function AgeYears(datDate1 As Date, datDate2 As Date) As Integer
        AgeYears = DateDiff("yyyy", datDate1, datDate2) + (Format(datDate1, "mmdd") > Format(datDate2, "mmdd"))
    End Function
    Normally datDate1 would be the date of birth & datDate2 would be today's date so use the Date function for that. For example, someone born on 15 May 1982:
    Code:
    ?AgeYears(#5/15/1982#,Date())
    38
    If you want to read a lengthy discussion/argument on various approaches to calculating age, see https://bytes.com/topic/access/answe...invalid-syntax
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    raywhite is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    3
    Thank you that is helpful
    Quote Originally Posted by isladogs View Post
    Agree with June. Using an Age function to calculate Age in a query as needed.
    There are many different Age functions, some more complex than others.
    The one I use is probably the the most concise

    Code:
    Function AgeYears(datDate1 As Date, datDate2 As Date) As Integer
        AgeYears = DateDiff("yyyy", datDate1, datDate2) + (Format(datDate1, "mmdd") > Format(datDate2, "mmdd"))
    End Function
    Normally datDate1 would be the date of birth & datDate2 would be today's date so use the Date function for that. For example, someone born on 15 May 1982:
    Code:
    ?AgeYears(#5/15/1982#,Date())
    38
    If you want to read a lengthy discussion/argument on various approaches to calculating age, see https://bytes.com/topic/access/answe...invalid-syntax

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Post 5 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 08-08-2017, 11:33 AM
  2. Replies: 2
    Last Post: 07-21-2014, 08:47 AM
  3. how to auto update a report ?
    By joe55555 in forum Access
    Replies: 5
    Last Post: 08-29-2013, 01:08 AM
  4. Auto Update Question
    By LionsCricket in forum Access
    Replies: 3
    Last Post: 04-11-2013, 03:22 PM
  5. Auto Update Forms
    By Vikki in forum Forms
    Replies: 1
    Last Post: 02-09-2010, 10:51 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums