Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476

    Can I create this...?

    I've come back, but with a totally different database & a different subject. Basically, I have a DateOfBirth (DOB) field which the data type is Date. Within this Table (or in a query) how might I display the ages of the subjects (year of DOB) - the current year?

    EG.
    Subject Name: John Doe
    DOB: 5/3/1968
    Age: 43

    I'm not sure if this can be done?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Here's the function I use for age:
    Code:
    Public Function Age(DOB As Date) As Integer
       Age = DateDiff("yyyy", DOB, Date) + (Date < DateSerial(Year(Date), Month(DOB), Day(DOB)))
    End Function

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Don't put spaces or special characters in your field names...

    Your Table
    PersonName
    DOB
    ...

    Query

    Select PersonName, DateDiff("yyyy",Now(),DOB) as Age from YourTable

    Geez.. RuralGuy was answering while I was typing.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Sorry Orange. I didn't know you were typing.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    It's OK Allan, I didn't realize you were answering.

  6. #6
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Ok,

    Just to understand, in my Employees Info Table which has many field; one being an EmployeeID Field (Employees First & Last name abbreviated) & their DOB. Now, do I create an "Age" field in my main Employees Info Table & then do I pull these 3-fields into a query? And when you gave me the "Code" do I put that in SQL & where? I'm sorry for my ignorance & pestering you guys day-after-day; might you be a bit more specific?

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    In your Employees Table, you would have
    an Id field autonumber (unique for Access to use)
    FirstName text
    LastName text
    DOB date
    any other fields specific to Employee

    You would NOT store AGE - it can be calculated at anytime.

    You can put Allan's Age function in a query, or in vba if and where needed.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    To add to Orange's explaination, I would put the function I supplied in post #2 in a standard module. then in a query of your table I would have "SELECT FirstName, LastName, Age([DOB]) As MyAge FROM YourTable ... etc."

  9. #9
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    I'm sorry guys, I'm completely lost!!!

  10. #10
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    As everyone knows I'm talking out of my hat, but why wouldn't a DateDiff function work? Clueless I tried, Age: DateDiff(([DOB]-Now()))

    You're dealing with an Idiot obliviously...

  11. #11
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    <You can put Allan's Age function in a query, or in vba if and where needed>

    I don't understand how...? It's sooooooooooooo frustrating!!!

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Start by creating a Standard Module and put the Function I supplied in it. Can you do that?

  13. #13
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Quote Originally Posted by djclntn View Post
    As everyone knows I'm talking out of my hat, but why wouldn't a DateDiff function work? Clueless I tried, Age: DateDiff(([DOB]-Now()))

    You're dealing with an Idiot obliviously...

    This is the syntax for DateDiff

    DateDiff("yyyy",Now(),DOB)

    http://www.techonthenet.com/access/f...e/datediff.php

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What I posted is accurate to the DAY.

  15. #15
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Orange, Please, no offence to anyone else here who spend so much of their time & patience with me; I greatly appreciate ALL of you guys! The DateDiff("yyyy",Now(),DOB) was exactly what I was searching for; you hit the nail on the head! Thanks!!!

    One little tweak I would like to make if I can. The numbers are showing as a negative numbers, is there any way the “Age” numbers could be displayed as non-negative Numbers?

    For the record, I was only calling myself an idiot out of extreme frustration.

    Thanksagain to EVERYONE! :-)

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

Similar Threads

  1. How best to create this..
    By Mantaii in forum Database Design
    Replies: 12
    Last Post: 11-04-2011, 09:32 AM
  2. Can't create new Form
    By CASmith in forum Forms
    Replies: 7
    Last Post: 08-08-2011, 07:21 PM
  3. Create new fields
    By thart21 in forum Queries
    Replies: 7
    Last Post: 04-15-2010, 07:03 AM
  4. Need to create a new db
    By ori in forum Access
    Replies: 5
    Last Post: 05-26-2009, 05:24 AM
  5. create sequential id
    By proudestmnky1 in forum Programming
    Replies: 0
    Last Post: 12-16-2008, 12:10 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