Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    coolpal9 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    40

    Calculating Age from DOB

    Hi,



    In the form I have designed, I want the Age to be calculated and printed side-by-side when the DOB is entered.

    How shall I go about it?

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I have seen several ways of calculating the age from the date of birth. Here is one link

  3. #3
    coolpal9 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    40
    It is not giving the desired results.

    Pl suggest some other way out..

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    The solution offered by does work. If it is not working for you then you must be doing something wrong. The expression:-
    =DateDiff("yyyy",[Birthdate],Now())+Int(Format(Now(),"mmdd")<Format([Birthdate],"mmdd"))
    should be used as the Control Source for the textbox that is used to show the age.
    Birthdate should be changed to the name of the textbox that holds the DOB.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    coolpal9 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    40
    But still I don't get the age calculated. Instead, when I view the form in the form view, I get to see "#Name?" written in place of any age...
    Last edited by coolpal9; 01-09-2012 at 11:50 PM.

  6. #6
    Fatti is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    18
    Then you've got a variable misnamed, a spelling error or you have bound the field to something you shouldn't have or nothing.

    Could be a multitude of errors.

  7. #7
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Coolpal9,

    Is it possible for you to zip & post your database (with any sensitive data removed)? That way we can explore the issue further.

  8. #8
    coolpal9 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    40
    Yeah, there was a minor error.

    But after that, now the Age textbox always returns 113 as the result.

  9. #9
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by coolpal9 View Post
    Yeah, there was a minor error.

    But after that, now the Age textbox always returns 113 as the result.
    1. What is the datatype of the field where the birthdate is stored? Is it really a date/time field and not TEXT?

    2. How is the date stored? What is the date format that you use in the database?

    You might need to format to U.S. date format if you are not in the U.S. (thank Microsoft for that one):

    =DateDiff("yyyy",[Birthdate],Format(Date(),"\#mm\/dd\/yyyy\#")+Int(Format(Date(),"\#mm\/dd\/yyyy\#"<Format([Birthdate],"mmdd"))

    And I would use DATE() instead of NOW because that eliminates the time element which you aren't concerned with anyway.

  10. #10
    coolpal9 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    40
    It is date/time.

    Format is mm/dd/yyyy

  11. #11
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by coolpal9 View Post
    I have uploaded the project.

    Pl check...
    Doesn't look like anything attached. Did you remember to run Compact and Repair and then ZIP the file (with Windows XP or above you can just right-click on the file and select SEND TO > COMPRESSED FOLDER).

  12. #12
    coolpal9 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    40
    Check the attachment...

  13. #13
    coolpal9 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    40
    It shows #Error. I don't know what syntactic error is there. I've checked it many times.

    Pl help...

  14. #14
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    The name of your DOB control is not DOB but rather DOB_Text. You have to use DOB_Text in the expression. Corrected DB is attached.

  15. #15
    coolpal9 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    40

    Post

    Thank you!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculating Time
    By jlclark4 in forum Forms
    Replies: 0
    Last Post: 04-25-2011, 09:04 AM
  2. Calculating Networkdays
    By jsiketa in forum Queries
    Replies: 1
    Last Post: 06-10-2010, 06:05 PM
  3. Calculating the column value
    By access in forum Queries
    Replies: 6
    Last Post: 08-20-2009, 11:51 AM
  4. Calculating the sum of every four records.
    By Alanlives in forum Queries
    Replies: 0
    Last Post: 07-31-2009, 05:56 AM
  5. Calculating Values
    By Jahan in forum Queries
    Replies: 1
    Last Post: 07-09-2006, 09:15 AM

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