Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-14-2014, 10:38 AM
Xaand Xaand is offline Age calculation with date and DOB fields Windows Vista Age calculation with date and DOB fields Office 2007
Novice
Age calculation with date and DOB fields
 
Join Date: Feb 2014
Posts: 4
Xaand is on a distinguished road
Default Age calculation with date and DOB fields

Hi!
I must state that I am by no means trained in any form of programming/coding. What I have learned over the past week, I have done by finding information on the internet.

Here is what I am trying to achieve:


1. I am currently developing a form and I want the age to be calculated based on the current date and the DOB entered by the individual completing the form. The code I entered keeps on returning the age of the person rounded up. Ex: I entered April 8, 1981 as the DOB and the age returned is 33 instead of 32 (the person will only be 33 on April 8th of this year). I have included the Word document that I have been working with. Someone told me it might have something to do with updating fields (this means nothing to me J)
2. If the individual’s age is below 1 year of age, I would like the code to reflect the age in months. That being said the output would be “years” if they are over the age of 1, “year” if they are 1 year old, months if they are 2 to 11 months of age and “month” if they are 1 month old and “weeks” if they are only a few weeks old.
Any help would be appreciated. I have been working on this for a few days and I have no idea what I am doing J. I feel like the code in my word document should function, but I keep on getting a total that is off by 1.

Thank you!
Attached Files
File Type: docx coding_test.docx (21.8 KB, 58 views)
Reply With Quote
  #2  
Old 02-14-2014, 11:20 AM
Charles Kenyon Charles Kenyon is offline Age calculation with date and DOB fields Windows 7 64bit Age calculation with date and DOB fields Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I suspect you can find everything you need in the document attached to this thread:
Microsoft Word Date Calculation Tutorial

There are plenty of sample fields and instructions.
Reply With Quote
  #3  
Old 02-14-2014, 05:51 PM
macropod's Avatar
macropod macropod is offline Age calculation with date and DOB fields Windows 7 32bit Age calculation with date and DOB fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted and answered before posting here, at: http://answers.microsoft.com/en-us/o...4-ecddc708f64b
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 02-18-2014, 05:29 AM
Xaand Xaand is offline Age calculation with date and DOB fields Windows Vista Age calculation with date and DOB fields Office 2007
Novice
Age calculation with date and DOB fields
 
Join Date: Feb 2014
Posts: 4
Xaand is on a distinguished road
Default

Regarding the Tutorial, it does not really help me since I will not require all three (years, months, days) listed at once, I will require years for someone who is 1 year or older, months for an infant that is 4 weeks old to 11 months old and days for an infant that is below 1 month of age...

Yes, my friend posted that on my behalf, however, it does not solve the problem I am experiencing. I used "F9" to update the fields, and still I do not get the correct age. This is why I included the Word document to see if anyone could look at it and let me know what the issue is...

Thanks anyways though...
Reply With Quote
  #5  
Old 02-18-2014, 12:44 PM
Charles Kenyon Charles Kenyon is offline Age calculation with date and DOB fields Windows 7 64bit Age calculation with date and DOB fields Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

The tutorial will give you the answer. You do not have to display all of the results.
Reply With Quote
  #6  
Old 02-18-2014, 01:53 PM
macropod's Avatar
macropod macropod is offline Age calculation with date and DOB fields Windows 7 32bit Age calculation with date and DOB fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Xaand,

There are some fundamental problems with your attached document:
1. The field code you are using is NOT the same as the textual representation of it that appear in the document and that you have posted online. A glaring difference is that you've changed some of the switches in the field code to something quite incompatible with the calculations;
2. You have inserted the formfields inside content controls!!! Formfields and content controls are not meant to be used in the same document, let alone one inside the other.
Fix those issues and the calculation field will work correctly.

As for "it might have something to do with updating fields", the formfield 'calculate on exit property takes care of that. If you use content controls, though, a different approach would be required (e.g. a macro or Ctrl-A, F9).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 02-21-2014, 10:45 AM
Xaand Xaand is offline Age calculation with date and DOB fields Windows Vista Age calculation with date and DOB fields Office 2007
Novice
Age calculation with date and DOB fields
 
Join Date: Feb 2014
Posts: 4
Xaand is on a distinguished road
Default Thanks!

Hi!

I just wanted to thank you for all of the information you have provided me with. The tutorial I was referred to by Charles Kenyon and the "fundamental problems" pointed out by macropod, as well as searching on various forums, have allowed me develop a functional sheet! Yay!

I’ve never done anything like this before, so it was great to hear from people who had experience with these types of issues and who were willing to assist me.

Thanks again!
Reply With Quote
  #8  
Old 02-21-2014, 09:15 PM
Charles Kenyon Charles Kenyon is offline Age calculation with date and DOB fields Windows 7 64bit Age calculation with date and DOB fields Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You are welcome. We all started as beginners.
Reply With Quote
  #9  
Old 09-29-2023, 05:10 AM
JohnDohe JohnDohe is offline Age calculation with date and DOB fields Windows 7 64bit Age calculation with date and DOB fields Office 2010 64bit
Novice
 
Join Date: Mar 2015
Posts: 7
JohnDohe is on a distinguished road
Smile

Quote:
Originally Posted by Xaand View Post
Hi!

I just wanted to thank you for all of the information you have provided me with. The tutorial I was referred to by Charles Kenyon and the "fundamental problems" pointed out by macropod, as well as searching on various forums, have allowed me develop a functional sheet! Yay!

I’ve never done anything like this before, so it was great to hear from people who had experience with these types of issues and who were willing to assist me.

Thanks again!

Hi!


Like yourself, I too am a "newbie" to all this!


" field code" "textual representation" "switches in the field code" "inserted the formfields inside content controls" . . .
OMG! Way above my pay grade! LOL!


Could you share the exact coding your arrived at, in the context of an actual document you created?


Many thanks!
Reply With Quote
  #10  
Old 09-29-2023, 11:38 AM
Charles Kenyon Charles Kenyon is offline Age calculation with date and DOB fields Windows 11 Age calculation with date and DOB fields Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Look to the tutorial by Paul Edstein (macropod) that was linked above.
Microsoft Word Date Calculation Tutorial
It has ready-to go field coding, but read the introductory material.

See also the cross-posted question.
Redirecting

Additional resource: Dealing with Fields in Microsoft Word

Quote:
" field code" "textual representation" "switches in the field code" "inserted the formfields inside content controls" . . .
OMG! Way above my pay grade! LOL!
You are not asking about basic stuff. It is time to dig in and learn some. That is what the tutorial is for.
  • Fields in Word are dynamic bits in a document that can change based on other information without macros. In this case, a complex field changes its results based on a date input elsewhere and marked as a bookmark.
  • Fields have code that tells Word which field you are using and what you want it to do. The code and the switches may be specific to the field. There are online references for each field. List of field codes in Word
  • The textual representation is, I suspect, someone's typing what a field code looks like here - in text. Field codes are not text, exactly, in that the { } braces must be inserted by Word, not typed.
  • Field results are what you see on the screen when a field is updated and not displayed as code.
[Legacy] Formfields and Content Controls are two ways of getting information from a user. They should not both be used in the same document/template.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Age calculation with date and DOB fields Rules based due date calculation dlowrey Excel Programming 3 05-12-2013 08:30 PM
Age calculation with date and DOB fields calculation if either of two fields is entered BritBiker2 Excel 5 01-29-2013 09:12 AM
Age calculation with date and DOB fields Date Calculation Lights Excel 5 04-18-2012 04:31 AM
calculation of start date ketanco Project 1 02-29-2012 07:01 AM
how to make fields calculation variable according to the filter i use duraid Project 0 09-09-2010 01:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:17 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft