Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
larune - 05 Jul 2005 13:59 GMT
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?
Scott L. Heim [MSFT] - 05 Jul 2005 15:28 GMT
Hi,

To execute date calculations in InfoPath you will need to write custom code
- take a look at the following BLOG entry as it should provide what you
need:

http://blogs.msdn.com/infopath/search.aspx?q=date+calculation&p=1

Best Regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
S.Y.M. Wong-A-Ton - 10 Feb 2006 15:04 GMT
It is possible to use rules and functions within InfoPath to calculate a
person's age from a given date of birth. A possible solution for this
calculation without custom code has been posted here:
http://enterprise-solutions.swits.net/infopath/calculating-age-from-date-of-birth.htm
---
S.Y.M. Wong-A-Ton

> 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?
Bob B - 11 Feb 2007 22:06 GMT
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.

> It is possible to use rules and functions within InfoPath to calculate a
> person's age from a given date of birth. A possible solution for this
[quoted text clipped - 6 lines]
> > date-picker field.  can this be done with Infopath field rules,  or do I need
> > to invoke VB?
S.Y.M. Wong-A-Ton - 19 Feb 2007 11:36 GMT
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.net/infopath2003/article.php?t=calculating-age
-from-date-of-birth&c=infopath2003


Hope that works for you now.
---
S.Y.M. Wong-A-Ton

> 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
[quoted text clipped - 11 lines]
> > > date-picker field.  can this be done with Infopath field rules,  or do I need
> > > to invoke VB?
Bob B - 19 Feb 2007 14:03 GMT
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.

> Sorry for the delay in responding, and thank you for pointing out the
> mistake. Actually, the article contained several mistakes.
[quoted text clipped - 25 lines]
> > > > date-picker field.  can this be done with Infopath field rules,  or do I need
> > > > to invoke VB?
S.Y.M. Wong-A-Ton - 20 Feb 2007 08:43 GMT
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.
---
S.Y.M. Wong-A-Ton

> 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
[quoted text clipped - 30 lines]
> > > > > date-picker field.  can this be done with Infopath field rules,  or do I need
> > > > > to invoke VB?
Bob B - 21 Feb 2007 22:00 GMT
I finally got it to work. Thanks for staying with me.

> 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
[quoted text clipped - 43 lines]
> > > > > > date-picker field.  can this be done with Infopath field rules,  or do I need
> > > > > > to invoke VB?
S.Y.M. Wong-A-Ton - 22 Feb 2007 07:16 GMT
Well done! And no problem. :)
---
S.Y.M. Wong-A-Ton

> I finally got it to work. Thanks for staying with me.
>
[quoted text clipped - 45 lines]
> > > > > > > date-picker field.  can this be done with Infopath field rules,  or do I need
> > > > > > > to invoke VB?
Bobby - 02 Aug 2007 23:52 GMT
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!

> Well done! And no problem. :)
> ---
[quoted text clipped - 49 lines]
> > > > > > > > date-picker field.  can this be done with Infopath field rules,  or do I need
> > > > > > > > to invoke VB?
S.Y.M. Wong-A-Ton - 03 Aug 2007 07:34 GMT
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.
---
S.Y.M. Wong-A-Ton

> 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
[quoted text clipped - 53 lines]
> > > > > > > > > date-picker field.  can this be done with Infopath field rules,  or do I need
> > > > > > > > > to invoke VB?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.