Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2011, 03:20 AM
tsindos tsindos is offline Adding months to a Date Windows 7 32bit Adding months to a Date Office 2010 32bit
Novice
Adding months to a Date
 
Join Date: Sep 2011
Posts: 3
tsindos is on a distinguished road
Unhappy Adding months to a Date

I have found the following piece of code on the Internet and used it fine on my previous computer. Now that I changed computer, I cannot get it to work. I have not found anything relating to this in past threads in this forum.

The Idea is to add 36 (Delay) months to a date entered (StartDate).

The code is:



{QUOTE
{SET mm{=MOD(ABS({StartDate \@ M}+Delay+11);12)}}
{SET yy{=INT({StartDate \@ yyyy}+(Delay+{StartDate \@ m}-1)/12)}}
{SET dd{=IF(({StartDate \@ d}>28)*({mm \@ M}=2)=1;28+((MOD(yy;4)=0)+(MOD(yy;400)=0)-(MOD(yy;100)=0));
IF(({mm \@M}=4)+({mm \@ M}=6+({mm \@ M}=9)+({mm \@ M}=11)+({StartDate \@ d}>30)>1;30;{StartDate \@ d}))}}
{IF{={IF{={StartDate \@ “dddd”}}=”!*” 0 1}+{IF{={StartDate \@ “MMMM”}}= “!*” 0 1}+{IF{a}=”!*” 1 0}+{IF{=Delay}=”{Delay}” 0 1}}=0
{QUOTE “{dd}-{mm}-{yy}” \@ “dddd, d MMMM yyyy”}.” “Data entry error!”}}

Can anyone help me figure out what I am doing wrong?

Thank you.
Reply With Quote
  #2  
Old 09-28-2011, 03:25 AM
OTPM OTPM is offline Adding months to a Date Windows 7 32bit Adding months to a Date Office 2010 32bit
Expert
 
Join Date: Apr 2011
Location: West Midlands
Posts: 981
OTPM is on a distinguished road
Default

Hi
Can you post a copy of your document with the code embedded so we can take a look for you.
Tony(OTPM)
Reply With Quote
  #3  
Old 09-28-2011, 03:30 AM
tsindos tsindos is offline Adding months to a Date Windows 7 32bit Adding months to a Date Office 2010 32bit
Novice
Adding months to a Date
 
Join Date: Sep 2011
Posts: 3
tsindos is on a distinguished road
Default Copy of Document

Does this help?
Attached Files
File Type: docx Period of hire.docx (25.6 KB, 10 views)
Reply With Quote
  #4  
Old 10-03-2011, 05:20 AM
macropod's Avatar
macropod macropod is online now Adding months to a Date Windows 7 64bit Adding months to a Date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Hi tsindos,

That code comes from my Microsoft Word Date Calculation Tutorial, at:
http://lounge.windowssecrets.com/ind...owtopic=249902
or
http://www.gmayor.com/downloads.htm#Third_party

It would appear that you've tried to combine a field code from the tutorial that used error-checking with the field for adding months to a date, and got some of the syntax wrong - specifically, a '(' before the first 'Delay' reference. If your formfield has data entry validation, you don't need the additional error-checking code, and it can be reduced to:
{QUOTE
{SET mm{=MOD(ABS({StartDate \@ M}+Delay+11);12)+1}}
{SET yy{=INT({StartDate \@ yyyy}+(Delay+{StartDate \@ M}-1)/12)}}
{SET dd{=IF(({StartDate \@ d}>28)*(mm=2)=1;28+((MOD(yy;4)=0)+(MOD(yy;400)=0)-(MOD(yy;100)=0));IF((mm=4)+(mm=6)+(mm=9)+(mm=11)+( {StartDate \@ d}>30)>1;30;{StartDate \@ d}))}}
"{dd}-{mm}-{yy}" \@ "dddd, d MMMM yyyy" \* Charformat}

Note that I've bolded the 'Q' in 'QUOTE' and added a Charformat switch. That's the correct way to alter the field's formatting - not by trying to apply bold formatting to the lot (which often adds numerous unhelpful Mergeformat switches).

Also, your formfields need the 'calculate on exit' property set, otherwise, the calculation won't occur.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 10-04-2011, 11:20 PM
tsindos tsindos is offline Adding months to a Date Windows 7 32bit Adding months to a Date Office 2010 32bit
Novice
Adding months to a Date
 
Join Date: Sep 2011
Posts: 3
tsindos is on a distinguished road
Default

Thank you very much Paul. It seems you know your Word.

I cannot test your code since i am away from my work computer for 2 days. I will test it later this week and update you.

Thanks again
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding months to a Date Adding Image into a excel cell and adding a hyperlink to the image saravananiyyanar Excel 3 05-04-2011 08:31 AM
Adding months to a Date chart with months windseaker Excel 1 04-29-2011 11:45 PM
Setting up recurring months to skip some months etc. dwelch@ykfireprevention.c Outlook 0 11-30-2010 10:15 AM
new appointment date always reverts back to today's date msills Outlook 0 08-24-2007 08:57 AM
Adding months to a Date Imported message date change to today's date promark Outlook 1 12-23-2005 07:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:24 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