Infopath: how do I calculate "age" from d.o.b. date-picker field

L

larune

I need a form that calculates date field from date of birth entered as a
date-picker field. can this be done with Infopath field rules, or do I need
to invoke VB?
 
B

Bob B

I followed you instructions to calculate a person's age. Except under the
conditon for action 3. It would not except Set a field's value: age < 0. I
changed to age< 0. When I put in a date nothing show in the dob field.
Could I have a syntax error? or what.
 
S

S.Y.M. Wong-A-Ton

Sorry for the delay in responding, and thank you for pointing out the
mistake. Actually, the article contained several mistakes.

There is no set a field's value for conditions. You need to just select
"age" from the first drop-down, "is less than" from the second, and type in
zero in the text field when you're in the Conditions dialog box.

I've corrected the article to contain slightly less faulty instructions. See
http://enterprise-solutions.swits.n...ulating-age-from-date-of-birth&c=infopath2003

Hope that works for you now.
 
B

Bob B

I had figured out the fix for the 3rd action. Now I'm getting the error
"Some rules are not applied, uspecified error" This is occuring on the 2nd
action conditions, because when I bypass error the age is not being calculate
right when DOB is in some month or year.
 
S

S.Y.M. Wong-A-Ton

Did you create the form from scratch by following the instructions? Or are
you trying to incorporate it in a form you already had? It could be that the
location of your nodes in the main data source differ from what is specified
in the article. Other than that, I cannot think of anything.

I've recreated the form for you and posted it here:
http://enterprise-solutions.swits.net/infopath2003/calcagedob.zip

I will remove this link soon! Download the file, unzip it, right click on
the XSN and choose Design.
 
B

Bobby

Your instructions for this work great! However, I have the need to calculate
the age in months and not years. What rule should I delete/add/change to do
this? Thanks!
 
S

S.Y.M. Wong-A-Ton

You could change both age actions to multiply by 12. For example, the first
action would become

age = (number(substring(today(), 1, 4)) - number(substring(., 1, 4))) * 12

and the second one would become

age = (number(substring(today(), 1, 4)) - number(substring(., 1, 4)) - 1) * 12

But this would not give you the amount of months to date. The logic to do
that would become too complex for rules, so I would recommend writing code if
you want to calculate the exact amount of months until the day of today.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top