Dear Sir/Madam
I am using access 97 and would want a visual basic function that I can use to enter(Calculate) the age of a person based on the date of birth and the current date, that is in a text box.
Gots
Printable View
Dear Sir/Madam
I am using access 97 and would want a visual basic function that I can use to enter(Calculate) the age of a person based on the date of birth and the current date, that is in a text box.
Gots
Have you tried something like the following:
I use something similar in some of my programs. You could modify it to check if DateOfBirth is really a date, modify the results (the formatting) or whatever.Code:public function age(DateOfBirth) as integer
age = ((date() - DateOfBirth) / 365.25)
end function
Hope this helps...
pryear = Year of today's date
prmonth = Month of today's date
prday = Day number of today's date
psyear = Year of Past date
psmonth = Month of Past date
psday = Day number of Past date
1.First check today's date is greater than Entered date.
2.Calculate totyears=pryear-psyears
3.check psmonth<prmonth
if yes
totyears=totyears-1
totmonths=(12-psmonth+prmonth)
if no
totmonths=prmonth-psmonth
4.check psday<prday
if yes
{
check totmonths=0
if yes
totyears=totyears-1
totmonths=11
if no
totmonths=totmonths-1
totdays=(30-psday+prday)
}
if no
totdays=prday-psday
5.Display output :
totyears & " years " & totmonths & " months " & totdays & " days"
use the following code
Code:
YourDte = Cdate("TextBox??")
Days = Date - YourDte
Years = Days / 365