Results 1 to 4 of 4
  1. #1
    kymwilkinson is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    2

    Calculating Ages

    I am new at Access. We are using Access 2013. Our database contains client information including DOB. We are required to report various numbers as related to specific "groups". One of them is "Elderly" and that group is defined as anyone over the age of 60. The following expression was created within a query that also reports the number of Youth, Female, etc. (I did not write the expression):



    Elderly: IIf([ClientDOB] Is Null,0,IIf((DateDiff("yyyy",[ClientDOB],Date())>60),1,0))

    The problem is that it is not calculating to the birthdate. So that if someone has a birthdate of 5/25/1955, they turned 60 yesterday, but it does not count them as "Elderly". It doesn't appear to me that it will count them until the end of the year.

    I am having the same issue with the "Youth" expression, which is supposed to define anyone under 18:

    Youth: IIf([ClientDOB] Is Null,0,IIf((DateDiff("yyyy",[ClientDOB],Date())<18),1,0))

    Any suggestions for this newbie?
    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    They are 60, not 'over 60'. If you want to count fractions of year, that gets complicated.

    Review https://www.accessforums.net/access/...day-15274.html
    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
    kymwilkinson is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    2
    I don't know what happened to my previous replies, so I will just sum them up here. I had tried the link June7 provided and had errors in the syntax. I just found another piece of code in another forum that made me think if I changed the "yyyy" to "d" to represent the number of DAYS they were, that while not perfect in all situations, it was much more accurate than asking for a calculation on years. So the new expression is Elderly: IIf([ClientDOB] Is Null,0,IIf((DateDiff("d",[ClientDOB],Date())>21915),1,0))
    This would be the number of days old (60 x 365.25).
    And then
    Youth: IIf([ClientDOB] Is Null,0,IIf((DateDiff("yyyy",[ClientDOB],Date())<6574),1,0))
    Number of days old (18 x 365.25). I did not use the decimal (6574.50 days) because I was afraid of another syntax error.

    The new RUN revealed all calculations are correct. This should greatly diminish the number of errors we we're receiving.

    Now to figure out how to "SOLVE" this issue on the forum!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Thread Tools dropdown above first post.
    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.

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

Similar Threads

  1. Replies: 9
    Last Post: 10-21-2013, 03:31 PM
  2. Counting guests based upon their ages
    By bellevue in forum Forms
    Replies: 3
    Last Post: 05-18-2012, 06:18 AM
  3. Closing down Access takes ages
    By bellevue in forum Access
    Replies: 4
    Last Post: 04-18-2012, 03:55 AM
  4. Calculating Age from DOB
    By coolpal9 in forum Forms
    Replies: 15
    Last Post: 01-12-2012, 05:26 AM
  5. Sort Calculated Ages in to Age Groups
    By l3111 in forum Queries
    Replies: 2
    Last Post: 06-09-2011, 04:33 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