Solved

Calculate approximate birthdate based on current age

Posted on 2014-03-20
18
262 Views
Last Modified: 2014-03-21
I have an Access 2010 database used to track information on animals that come into our shelter.  I need a way to keep better track of their age.  Currently we enter the age based on what age it was when it first came into contact with us.  Because we very rarely ever know the birthdate, the age is approximate based on our best guess.  The problem is that that age never changes no matter how long they've been here.  This is especially problematic for our animals less than a year old.  We have ages ranging from hours, days, weeks, months, to years.  I created a table a long time ago that converts the age they select from the drop down into years.  So when they choose 3 months it converts it into 0.25.  I'm using the field with the 0.25 data to figure out the birthdate using [BirthDate] = DateAdd("yyyy", -[Age], Date) but it only works if the animals is older than 1, otherwise it sees the age as zero and just enters today's date for the birthdate.  What do I need to change in order to make this work?

Thank you
0
Comment
Question by:animallover
  • 8
  • 5
  • 5
18 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39942961
why not add a birthdate field and insert approx. date if true date is unknown?
0
 

Author Comment

by:animallover
ID: 39942992
Because a lot of the time the person bringing them in doesn't know an approximate birthdate and will just say it's 8 years old.  I don't want the staff to have to then figure out what 8 years ago was.  Trust me, all sorts of wrong birthdates will be entered.
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39943030
if you leverage the date you first added the animal, you can derive the years.
do you store first-appointment date?
0
 

Author Comment

by:animallover
ID: 39943040
Yes.
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39943046
then age = DateDiff("yyyy", #3/4/2010#, Now())
substitute  #3/4/2010#, for your startdate field

don't store age. this is derived and displayed on the form/report.
0
 

Author Comment

by:animallover
ID: 39943080
If I had a start date field that related to its age i could do this but the start date field is the date of our first interaction with the animal.... it could already be many years old by then.
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39943099
if you enter an age field you can add this value to the difference in years between start-date and now

displayage = age +  DateDiff("yyyy", #3/4/2010#, Now())
0
 

Author Comment

by:animallover
ID: 39943279
That still doesn't work when the age is less than 1
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39943294
displayage = IIF(NZ(age,0)=0,1,age) +  DateDiff("yyyy", #3/4/2010#, Now())
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39944605
First, you should record the birthdate and not the age.

Then, let the user choose the unit of age: Hours, Days, Weeks, Months, Years.
If you use a combobox, let it have the columns:

"h";"Hours"
"d";"Days"
"ww";"Weeks"
"m";"Months"
"yyyy";"Years"

You will hide the first column and display the second.
The first column is used as the date interval to calculate the birthdate.

Now, calculate the birthdate from the selected interval and the value:

Me!DateOfBirth = DateAdd(Me!cboAgeUnit, -Val(Me!txtAge), Now)

/gustav
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39945575
animallover indicated they don't always know the date - hence the need to store approx. age.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39945591
No. They have the age, then will calculate and store the DOB.
Then the actual age can be calculated at any future date.

/gustav
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39945596
'Currently we enter the age based on what age it was when it first came into contact with us.  Because we very rarely ever know the birthdate, the age is approximate based on our best guess'
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39945612
Yes. And then:

> The problem is that that age never changes no matter how long they've been here.  
> This is especially problematic for our animals less than a year old.

Thus, calculate the (approximate) DOB, store that, and then the actual age can be retrieved at any time later.

/gustav
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39945628
displayage = IIF(NZ(age,0)=0,1,age) +  DateDiff("yyyy", #3/4/2010#, Now())  will derive/display the current 'age', based on the stored 'age' (years)

better still (based on original spec):
 [BirthDate] = IIF([Age] > 0, DateAdd("yyyy", -[Age], Date), 1)
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39945664
Except for the syntax error, that would require the age to be stored relative to 2010-04-03.
Further, you won't have the age with a resolution less than one year.
Finally, the age would only change with the calendar year.

My method is much simpler and won't fail.

/gustav
0
 

Author Closing Comment

by:animallover
ID: 39945720
Yes... we don't really need an accurate birthdate for animals over a year old but for those less than 6 months there are a lot of determinations made for that animal where age is a big factor.  We need to both be able to figure out the birthdate from the age at first interaction and then be able to update the age based on that birthdate.  Age is much more important to the end user and needs to be readily seen and available without having to go to a calendar to figure it out.  I was already using a combo box for the age but it wasn't broken down into columns as you suggested.  I am going to change it to your suggestion (Gustav) and give it a go.  Thank you for your solution!
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39945781
You are welcome!

/gustav
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now