Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    DPrugh is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Location
    Manchester, ME
    Posts
    10

    Question Calculate person's age based on the person's birth year and a table showing current year.


    If I use =2016-[BirthYr] it works, but I don't want the users to go into the design view on the form to change the year.
    The user may change the CurrentYr in a table called 'Current Semester'.
    There must be a way to use the Year function. Any ideas?

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You can use:

    =Year(Date())- [BirthYr]


    but it is not really accurate if my birthday is in November.....

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Simply subtracting the Year of Birth from the current year is not necessarily going to give you an accurate age! As Steve suggested, that will only work if the person has already had their birthday for the current year!

    Here are three Formulas commonly used for an accurate calculation like this:

    Code:
    DateDiff("yyyy", [DOB], Date) - IIf(Format$(Date, "mmdd") < Format$([DOB], "mmdd"), 1, 0)


    Code:
     DateDiff("yyyy", [DOB], Date()) +  Int( Format(Date(), "mmdd") < Format([DOB], "mmdd") )


    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    DPrugh is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Location
    Manchester, ME
    Posts
    10
    I don't know the date - only the year
    I tried Steve's idea, but I get a #Name? error

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by DPrugh View Post

    ...I don't know the date - only the year...
    Then you can't reliably calculate a person's age!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    DPrugh is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Location
    Manchester, ME
    Posts
    10
    These people are >65 yrs old, so we are only interested in +/- a year.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Oops, I need to learn how to read slower.... or comprehend faster. Or both.

    The user may change the CurrentYr in a table called 'Current Semester'.
    In a table named "Current Semester" you have a field named "CurrentYr" that holds a year? it is a number?
    And users can change the year?

    Is there only one record with a year in it?
    If not, how do you know which record is the year?

    Maybe:
    Code:
    =Dlookup("CurrentYr", "[Current Semester]", "WhichRec = 'CurrentYear'") - [BirthYr]
    where the table name is "Current Semester", the field that has the year is named "CurrentYr" and there is a column named "WhichRec" that is a text field with "CurrentYear" as the value to find.


    Edit: What is the structure of table "Current Semester"?


    BTW, shouldn't use spaces in object names.......

  8. #8
    DPrugh is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Location
    Manchester, ME
    Posts
    10
    I'll try again: Structure
    Sem 162
    Prev_Sem 154
    Prior_Sem 152
    CurrentYr 2016

  9. #9
    DPrugh is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Location
    Manchester, ME
    Posts
    10
    It's the 4th record in the table

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Does every record have 2016 in the field "CurrentYr"??

    How would I know which record to get the year from??

  11. #11
    DPrugh is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Location
    Manchester, ME
    Posts
    10
    It's the 4th record in the table
    The form for this person shows BirthYr
    The next field: Age is calculated by reading the 4th record in the CurrentSemester table - BirthYr

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The problem is that a table has no inherent order. Just because a record is the 4th record right now, doesn't mean it will be the 4th record tomorrow or the next day.
    To be able to select a specific record, there needs to be something specific that can be found that says "This is the correct record to use. Now get the value from the field named 'CurrentYr' ".

    Maybe you could post your dB???
    Last edited by ssanfu; 01-22-2016 at 01:48 PM.

  13. #13
    DPrugh is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Location
    Manchester, ME
    Posts
    10
    The CurrentYr (2016) will always be in the 4th record until I change it to 2017.

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Read Post #16 again.
    Then read it again.

    A table HAS NO ORDER. Until you can tell me to find a specific record using data in a field, I can't help any more.

    For example, if table had a field for "userID", and you said "Get the "CurrentYr" where the userID = 22", that can be done. But not "Get the "CurrentYr" in the 4th record", because the record might not be the 4th record tomorrow..... if/when you do a "Compact and Repair", the record might not be the 4th record.


    Good luck with your project.
    Last edited by June7; 01-22-2016 at 05:00 PM.

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    As has been pointed out - need parameter based on data to identify record.

    Your data structure example appears to have two fields.
    Sem 162
    Prev_Sem 154
    Prior_Sem 152
    CurrentYr 2016
    field1 field2
    Sem 162
    Prev_Sem 154
    Prior_Sem 152
    CurrentYr 2016

    =DLookup("field2", "[Current Semester]", "field1 = 'CurrentYr'") - [BirthYr]

    If this is not the structure then please provide example dataset.
    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.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-13-2015, 02:06 PM
  2. Replies: 3
    Last Post: 06-22-2015, 06:36 AM
  3. Replies: 7
    Last Post: 06-07-2015, 11:57 PM
  4. Replies: 1
    Last Post: 04-20-2015, 03:22 PM
  5. Replies: 3
    Last Post: 05-06-2014, 11:38 PM

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