Calculating number of years from a given date to now

  • Thread starter Thread starter BabyDaddy
  • Start date Start date
B

BabyDaddy

HELP, I have a database that stores birth dates and anniversary dates. I
also have a field called NumYears. I would like to calculate the number of
years an individual is married and display it in the NumYears field. This is
not something that needs to be stored, just displayed accurately each time
the form or query is run.
Thanks
 
See:
http://allenbrowne.com/func-08.html

The article explains why some common approaches do not work, and the
function returns the number of whole years at any date. For example if you
have a field named MarriageDate, put this in the Control Source of your text
box to show the number of years married:
=Age([MarriageDate])
 
Allene Brown, thanks for your input. I don't really understand how what u
said works. I wa hoping to get just a function that comprises of one line
that I would place in the query or control source. When I put in your
function "Age=([marriageDate]), it gives me an error. I have changed
MarriageDate to the field in my database but I don't have a field called age
and I get an error - "Undifined Function 'Age' in expression".
I'm a newbie at this so 'simply' does it...Thanks
 
1. Click the Modules tab of the Database window.
Click New.
Access opens a new module.

2. Paste in the code (the code from "Function ..." to "End Function".)

3. Make sure Access understands it by choosing Compile on the Debug menu.

4. Save the module with a name such as Module1.

You can now use it in the Control Source of your text box, but the = comes
first, i.e.:
=Age([DateOfMarriage])
and replace DateOfMarriage with whatever your field is actually called.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

BabyDaddy via AccessMonster.com said:
Allene Brown, thanks for your input. I don't really understand how what u
said works. I wa hoping to get just a function that comprises of one line
that I would place in the query or control source. When I put in your
function "Age=([marriageDate]), it gives me an error. I have changed
MarriageDate to the field in my database but I don't have a field called
age
and I get an error - "Undifined Function 'Age' in expression".
I'm a newbie at this so 'simply' does it...Thanks
HELP, I have a database that stores birth dates and anniversary dates. I
also have a field called NumYears. I would like to calculate the number
of
years an individual is married and display it in the NumYears field. This
is
not something that needs to be stored, just displayed accurately each time
the form or query is run.
Thanks
 
Back
Top