auto calc age and days

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two things i need help with. the first is how do I get calculate age
based on DOB and current date? I have tried using the code from Allen using a
module, but all my age box displays is #name? I have also tried to use the
expression I found in the forums, but access deletes it as soon as I close
the properties for the AGE box. I don't know a lick of code, so I don't know
what I need to change to make the code match my fields. The fields are DOB
and AGE.

My other problem is basically the same, but I need to calculate how many
days between BOOKING DATE field and RELEASE DATE field, and auto fill the
TOTAL DAYS field

Thanks for any help you can give me.
 
When you copied Allen's code, what did you name the module in which you
saved it? It cannot have the same name as the function itself.
 
I changed the name to "calc DOB" I still get the #Name? in the age field. do
I need to change something in the code to make it match my fields? the Module
goes in the AGE control source right? Sorry, I don't know a thing about
coding.
 
Ok try the following:
For Age calculation in your AGE-field of your form:

=Int((Date()-[DOB])/365)

For the Total Days field:

start in your query in the Field Line on the next free row:
(DateDiff("d",[BOOKING DATE],[RELEASE DATE])+1)

You need the "+1" if you counting the BOOKING DATE as first day. Ommit the
first "(" and the "+1)" when starting to count the firts day after the
BOOKING DATE.

Have a good day.
 
That's not as accurate as Allen's approach (especially for older people!),
nor the suggestions made in http://www.mvps.org/access/datetime/date0001.htm
at "The Access Web"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


bernie said:
Ok try the following:
For Age calculation in your AGE-field of your form:

=Int((Date()-[DOB])/365)

For the Total Days field:

start in your query in the Field Line on the next free row:
(DateDiff("d",[BOOKING DATE],[RELEASE DATE])+1)

You need the "+1" if you counting the BOOKING DATE as first day. Ommit the
first "(" and the "+1)" when starting to count the firts day after the
BOOKING DATE.

Have a good day.



metlkelley said:
I changed the name to "calc DOB" I still get the #Name? in the age
field. do
I need to change something in the code to make it match my fields? the
Module
goes in the AGE control source right? Sorry, I don't know a thing about
coding.
 
Sorry: I don't understand what you mean by "the AGE control source".

Open a new Module.

Copy the code from Allen's page into that module (The first line you copy
should be the one that starts "Function Age(varDOB ...", and the last line
you copy should be "End Function")

Save the Module as mdlAge.

Use Age as a function call in your query.
 
Back
Top