Jump to content

Age Calculation


tmac

This topic is 8591 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I use the following calc field for age:

NumToText(Year(Today) - Year(dob)- Case(Today< Date(Month(dob), Day(dob), Year(Today)), 1, 0)) & "/ " &

NumToText(Mod(Month(Today) - Month(dob) + 12 - Case(Day(Today) < Day(dob), 1, 0), 12))

It works beautifully except for one thing, until the user enters dob, the calc field shows a nonsense year that is distracting. I understand the concept of

"not IsEmpty" but since I didn't write the calculation I'm using, I hesitate to play around with it for fear of ending up with a mess that no longer calculates rather than the ideal situation where the age field waits for all relevant data before displaying.

Can anyone help?

Link to comment
Share on other sites

Yeah... first thing to do is backup the database with the Save a Copy As command. Now you don't have to worry about buggering anything up!

Second thing, I also "backup" a complicated calculation field (using the duplicate button in the Define Fields dialog box) and work on this one. When I have it working I copy the new calculation and paste it into the original field. Then delete the duplicate field. (If I bugger it I just delete the field and try again by dup-ing the original once more.)

I try to avoid the Today function and use Status[CurrentDate] and Status[CurrentTime] instead. These functions are better because they can be re-evaluated at any time: Today is only evaluated when the database first opens, which is a bummer if you leave the program running for a cople of days -- it will be wrong.

To solve the "nonsense year" appearing before a dob is entered, just nest the whole calculation in a case[] function...

Case[isEmpty[dob], "",

NumToText(Year(Today) - Year(dob) - Case(Today< Date(Month(dob), Day(dob), Year(Today)), 1, 0)) & "/ " &

NumToText(Mod(Month(Today) - Month(dob) + 12 - Case(Day(Today) < Day(dob), 1, 0), 12))

]

Link to comment
Share on other sites

This topic is 8591 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.