I am trying to calculate the age of our boys when they enter our program.
This neds to be done on a form and stored in a table.
The table is tblMain
The feilds are "Date of Birth" "Date of Entrance" and "Age at Entrance"
I have read the previous posts and can't seem to make sense of them.
Please let me know where I need to enter the code and what needs to be
entered. I have tried the DateDiff function but I can't figure it out.
tblMain should have a column for [Date of Birth] and one for [Date of
Entrance]. These values can be entered by the users into bound textboxes,
calendar control, date combo box, etc.
[Age at Entrance] should not get stored anywhere in the database, because it
is a calculated value. Nor should it be updatable by the users.
For the [Age at Entrance] text box on your form, goto the "ControlSource"
property and enter this expression:
= DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
Where interval should be "yyyy" to indicate you're counting years
Where date1 is the Date of Birth
Where date2 is the Date of Entrance
The last two arguments are optional.
I would recommend using this expression as your ControlSource for your [Age
at Entrance] value:
= DateDiff("yyyy", [Date of Birth], [Date at Entrance])
As long as the form contains bound controls for [Date of Birth] and [Date at
Entrance], then this will automatically display the Age at Entrance as the
result of the calculation.
You can goto Microsoft Access Help and search on the word, DateDiff
--
Peace & happy computing,
Mike Labosh, MCSD
"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane