Current Age from birthday field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • timgeitz
    New Member
    • Oct 2006
    • 5

    Current Age from birthday field

    I need a box on my form that computes a person's age using their birthday field entered on the same form (and stored in the table). The current age doesn't need to be stored in a table. I just want it to be visible so that I don't have to do the figuring in my head. Suggestions on the expression that would be needed to show the current age?

    I am using Access 2003 with Windows XP in English.

    Thanks, Tim
  • smitchcoff
    New Member
    • Oct 2006
    • 3

    #2
    Hey, take a look at the datediff function. If you search the help file, something should come up... Maybe something like:

    lbl_age = datediff('yyyy' , cboBirthDate, date)

    for more info/syntax, check out:
    http://www.techonthene t.com/access/functions/date/datediff.php

    Hope this helps!

    Originally posted by timgeitz
    I need a box on my form that computes a person's age using their birthday field entered on the same form (and stored in the table). The current age doesn't need to be stored in a table. I just want it to be visible so that I don't have to do the figuring in my head. Suggestions on the expression that would be needed to show the current age?

    I am using Access 2003 with Windows XP in English.

    Thanks, Tim

    Comment

    • PEB
      Recognized Expert Top Contributor
      • Aug 2006
      • 1418

      #3
      And also I can say that it's better to check the Access forum this post is largely discussed

      :)

      Comment

      • radio1
        New Member
        • Oct 2006
        • 14

        #4
        The following works for me (in Access 2002) -- my Date-Of-Birth field is called "dob". This formula prevents "error" strings from appearing in the calculated age field when the dob field hasn't yet been entered or is invalid.

        Code:
        =IIf(Nz([dob],"")="","",DateDiff("yyyy",[dob],Now())+(Now()<DateSerial(Year(Now()),Month([dob]),Day([dob]))))
        Hope this helps,

        radio1

        Comment

        • timgeitz
          New Member
          • Oct 2006
          • 5

          #5
          Radio, thanks for the coding, it worked fine just the way you had it with my fireld change.

          Blessings,
          timgeitz

          Comment

          • radio1
            New Member
            • Oct 2006
            • 14

            #6
            You're welcome.

            Please note that there are possibly "bigger/better/stronger/faster" ways of doing it -- I'm still quite new at Access and VBA coding. You just happened to ask the one question in the entire forum that I was apparently qualified to answer!

            Cheers,

            -radio1

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              That's how it works for all of us radio1.
              (Excluding MMcCarthy of course who's just a posting machine of all known Access issues - My hat is permanently off ;-) )
              Just reply to the ones that we can help on, which is what you did - so ups to you on that.

              Comment

              • PEB
                Recognized Expert Top Contributor
                • Aug 2006
                • 1418

                #8
                Hi,

                First the function

                IIf(Nz(#23/03/2000#,"")="","" ,"") a test like this gives me an error:
                wrong number of arguments for the function nz()

                Nz() is used like : nz(#23/03/2000#) or nz("23/03/2000") only with one argument...

                But this part of the function isn't important coz it verifies if there is a birthdate introduced... So keep a part...

                The rest of the function is:

                DateDiff("yyyy" ,"23/03/2000",Now())+(D ateSerial(Year( Now()),Month("2 3/03/2000"),Day("23/03/2000")))

                With string values it doesn't give me correct results...

                with date values:

                the same result...

                But the function DateDiff("yyyy" ,"23/03/2000",Now()) gives just the age without monts and days...

                But after some verification you can use this one:

                =str(Datediff(" yyyy",Cvdate(Fo rmat("23/03/2000","DD/mm/yyyy")),Now())) +"/"str(Datediff(" m",Dateserial(Y ear(Now()),Mont h(Cvdate(Format ("23/03/2000","DD/mm/yyyy"))),Day(Cv date(Format("23/03/2000","DD/mm/yyyy")))),Now() ))+"/" +str(Datediff(" d",Dateserial(Y ear(Now()),Mont h(Now()),Day(Cv date(Format("23/03/2000","DD/mm/yyyy")))),Now() ))

                Have a nice evening!

                Originally posted by radio1
                The following works for me (in Access 2002) -- my Date-Of-Birth field is called "dob". This formula prevents "error" strings from appearing in the calculated age field when the dob field hasn't yet been entered or is invalid.

                Code:
                =IIf(Nz([dob],"")="","",DateDiff("yyyy",[dob],Now())+(Now()<DateSerial(Year(Now()),Month([dob]),Day([dob]))))
                Hope this helps,

                radio1

                Comment

                • PEB
                  Recognized Expert Top Contributor
                  • Aug 2006
                  • 1418

                  #9
                  radio 1 10x for the idea...

                  it was a very good way to find a short way to calculate it..

                  Before there was threads there , where we with mcarthy have created a long calculation functions about this...

                  And I wasn't able to begin a thread like the previous one....

                  But it was a very good idea...

                  :)

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    The optional second parameter to the Nz() function specifies the value to return if the first parameter evaluates to Null.

                    Thus
                    Code:
                    Nz([A], [B])
                    is equivalent to
                    Code:
                    IIf(IsNull([A]), [B], [A])

                    Comment

                    • PEB
                      Recognized Expert Top Contributor
                      • Aug 2006
                      • 1418

                      #11
                      I'm afraid but It gives me error on My Access...

                      And don't accept this optional argument...

                      But in this case it isn't a problem! It's unsignifcant for the function that calculates the age :)

                      So discuss it in different thread???
                      :)

                      Originally posted by NeoPa
                      The optional second parameter to the Nz() function specifies the value to return if the first parameter evaluates to Null.

                      Thus
                      Code:
                      Nz([A], [B])
                      is equivalent to
                      Code:
                      IIf(IsNull([A]), [B], [A])

                      Comment

                      Working...