Where did you type this?
The suggestion was to type it into the Control Source of a text box.
Do not include the [Age], i.e. the expression starts with =.
Also, you must use # around the date, not quotes.
See previous example.
Thank you for this. Unfortunately, I'm getting a run-time error 13 -
Type
Mismatch.
I entered
[Age] = Age([DateOfBirth], "9/21/2008")
I tried it with hash signs either side of the fixed date as well as "".
Sorry to be so thick.
:
1. Open the code window in Access.
2. On the Insert menu, choose Module.
Access opens a new code window.
3. Paste in everythin from Function ... to End Function.
4. To verify that Access understands it, choose Compile on the Debug
menu.
5. Save the module with a name such as Module1.
You can now use the function anywhere. For example, of you have a
field
named BirthDate, and want to know the person's age as of 21 Sep '08,
put
a
text box on your form and set its ControlSource to:
=Age([BirthDate], #09/21/08#)
(You should use the US format for the literal date, regardless of your
regional settings.)
Thank you for this. Unfortunately, I'm afraid I don't know how to
use
this
information. I copied and pasted the code into the After Update
event
but
got
an error.
Also, I couldn't see where to type in the specific date on which I
want
to
calculate the age. Is it the line:
dtAsOf = Date
so do I type my date in instead of 'Date'?
I'm afraid I'm really not too good with VB so idiot-proof
instructions
would
be really helpful if you've got the time, please.
:
See:
http://allenbrowne.com/func-08.html
The function takes 2 arguments:
- the birth date
- the date to calculate the age at.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
I would like automatically to calculate the age of people on a
specific
date
(21st September 2008, as it happens) by typing in their date of
birth.
I have tried the DateDiff function but this just appears to take
the
years
and people whose birthdays are after 21st September are aged by a
year.