Using a function

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

Guest

Hi
Had some reponses to my age date query.
I need to try out the functions suggested. I have pasted the functions in
the module but nothing happens in my table the column is empty and I expected
it to contain the calculated ages.
Could someone let me know how I get the code to run?
I bought a beginners book but it doesn't tell you how to do this
Help appreciated
Kim
 
Hi
Had some reponses to my age date query.
I need to try out the functions suggested. I have pasted the functions in
the module but nothing happens in my table the column is empty and I expected
it to contain the calculated ages.
Could someone let me know how I get the code to run?
I bought a beginners book but it doesn't tell you how to do this
Help appreciated
Kim

You should not store an age in your table at all. If you do, you know
for certain that every age in your table will be WRONG in no more than
a year!

Instead, store JUST the date of birth in your table. Use the Age
formula (see below) as a calculated field in a Query, or as the
Control Source of a textbox on a Form or Report. That way the age will
be calculated correctly whenever it's needed, based on today's date.

Age: DateDiff("yyyy", [DOB], Date()) - IIF(Format([DOB], "mmdd") >
Format(Date(), "mmdd"), 1, 0)

If you put this in a Query, you can sort by it, use it for searching,
display it on a form or report - anything except edit it (which you
wouldn't want to do anyway).

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top