View Single Post
 
Old 04-26-2018, 05:33 PM
fatal.lordes fatal.lordes is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Apr 2018
Posts: 6
fatal.lordes is on a distinguished road
Default Word document with VBA and Form Fields reset when select File,Print

Hi All

New to VBA for Word as well as forms for Word. Have created something that works great where a date is requested on file load, which then calculates dates on a form. Problem is, when we select File, Print, the dates all revert to original inputted date.

Sample of prompt to get date, place got date and one calculation from got date included below (I got this last one off the internet and it calculates the prior fortnight) is attached. Couldn't work out how to copy the code and paste in here so attachment was only option (sorry).

As said, everything works fine until I select File, Print. Even tried turning off "update fields when print" but made no difference.

Hoping someone can shed some light on the subject.



I found a macro that lets me copy out the field data. So below is the prompt to get the date to calculate from, then display the date entered, and then one of the calculations (basically each is the same except the second row changes to 12, to 11, to 10, etc, so a fortnight is done):

{ SET FNDATE { FILLIN "What is the Fortnight Ending (in DD/MM/YYYY format)" \@ "dd/MM/yyyy" } }

{ FNDATE }

{QUOTE
{SET Delay -13}
{SET a{=INT((14-{FNDATE \@ M})/12)}}
{SET b{={FNDATE \@ yyyy}+4800-a}}
{SET c{={FNDATE \@ M}+12*a-3}}
{SET d{FNDATE \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045+Delay}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
"{dd}-{mm}-{yy}" \@ " dd/MM/yyyy "}
Attached Files
File Type: docx sample fields.docx (23.9 KB, 7 views)

Last edited by fatal.lordes; 04-26-2018 at 06:05 PM. Reason: Added code.
Reply With Quote