Age Calculation....

alexkong2003

Registered User.
Local time
Today, 14:58
Joined
Sep 4, 2006
Messages
95
Hi,

I got a problem of displaying the age calculation... with a new entry form i have a field 'DOBirth' after user input the Birthday then the age will automatic calculate... the format no problem and age is able to count.... BUT there is unable to display the age after my calculation~~~

I just wonder how to do it...

My format is as following:
Code:
Me.Age = DateDiff("yyyy", [DOBirth], Now())


Any help will be greatly appreciated.

Thanks

regards,
alex
________________________________________________________________

**Hope someone able to help to solve the following thread as well, Thanks!

http://www.access-programmers.co.uk/forums/showthread.php?t=136310&highlight=Mixing+Number
 
Last edited:
Your post doesn't explain how you're trying to implement this code, although you keep referring to "format" which would not be the way. You need to place your code in the AfterUpdate event of your textbox that holds the DOB. Also, your code will not always give an accurate age. It will yield the difference between the year of birth and the current year, but if the person hasn't had his/her birthday for the current year, it'll be of! Here's code that will do the job:

Code:
Private Sub DOBirth_AfterUpdate()
  Me.Age =  Int(DateDiff("y", [DOBirth], Now()) / 365.237)
End Sub

And if you need for the age to be updated, as time passes:
Code:
Private Sub Form_Current()
  Me.Age =  Int(DateDiff("y", [DOBirth], Now()) / 365.237)
End Sub

Be sure to remove previous attempts at solving this before using this code.

Good Luck!
 
The age function I prefer is:
Code:
Public Function Age(DOB As Date) As Integer

Age = DateDiff("yyyy", DOB, Date) + (Date < DateSerial(Year(Date), Month(DOB), Day(DOB)))

End Function
 
Actually, I used that one for a long time, Allan, but ran across the one I posted which is, of course, shorter. I've tested it extensively and have never had it bomb!
 
Hi guys,

Thanks for the code! i made it!! the automatic display of the age had been done! u guys are genius!

Best Regard
alex
 
I hope that you used RuralGuy's . I used to work for AgeConcern a charity dealing with old folk and age calculations were key for us ao i did extensive testing, the best are those that work like us , ie take account of the birthday, all others fail around the birthdate.
I converted missinglinq's to a public function to test using specific dates

DOB 10/07/1998
date of calc 10/07/1999
age 0 returned
This was repeated for other samples.

But show the difficulty in testing

dob cdate age correct age
10/07/1959 10/07/1959 41 41

11/07/1959 10/07/1959 41 40


Brian
 
Last edited:
I'll go back to using my original one, which, as I said, was the same as Allan's!

Thanks!
 

Users who are viewing this thread

Back
Top Bottom