none
Year Calculation RRS feed

  • Question

  • Hi,

    is there a way to create a code that can provide the last 52 weeks of a "X"date?

    Example:

    I enter 03/30/2011 in .FormFields("Text1").

    i would to get a result on .FormField("Text2") a 52 weeks prior = 03/30/2010.

    Thanks


    Thanks Rewar
    Wednesday, March 30, 2011 5:40 PM

Answers

  • Run a macro containing the the following code on exit from the Text1 formfield.

    With ActiveDocument
       .Formfields("Text2").Result = DateAdd("y", -1, .Formfields("Text1").Result)
    End With


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "scorpdevil" wrote in message news:13384524-7bdc-4fbd-bfa0-c7dfbfcd2147@communitybridge.codeplex.com...

    Hi,

    is there a way to create a code that can provide the last 52 weeks of a "X"date?

    Example:

    I enter 03/30/2011 in .FormFields("Text1").

    i would to get a result on .FormField("Text2") a 52 weeks prior = 03/30/2010.

    Thanks


    Thanks Rewar


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by scorpdevil Thursday, March 31, 2011 2:17 PM
    Thursday, March 31, 2011 10:18 AM
  • For a 52 week offset, that needs to be:

    With ActiveDocument
      .FormFields("Text2").Result = DateAdd("ww", -52, .FormFields("Text1").Result)
    End With


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by scorpdevil Sunday, April 3, 2011 11:29 PM
    Thursday, March 31, 2011 8:42 PM

All replies

  • Word MVP macropod has written a great tutorial on date calculations in Word. You can download it from http://www.gmayor.com/downloads.htm#Third_party (see DateCalc.zip).


    Regards, Hans Vogelaar
    Wednesday, March 30, 2011 6:32 PM
  • Run a macro containing the the following code on exit from the Text1 formfield.

    With ActiveDocument
       .Formfields("Text2").Result = DateAdd("y", -1, .Formfields("Text1").Result)
    End With


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "scorpdevil" wrote in message news:13384524-7bdc-4fbd-bfa0-c7dfbfcd2147@communitybridge.codeplex.com...

    Hi,

    is there a way to create a code that can provide the last 52 weeks of a "X"date?

    Example:

    I enter 03/30/2011 in .FormFields("Text1").

    i would to get a result on .FormField("Text2") a 52 weeks prior = 03/30/2010.

    Thanks


    Thanks Rewar


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by scorpdevil Thursday, March 31, 2011 2:17 PM
    Thursday, March 31, 2011 10:18 AM
  • Doug,

    Very Nice! Thanks a lot.


    Thanks Rewar
    Thursday, March 31, 2011 2:17 PM
  • For a 52 week offset, that needs to be:

    With ActiveDocument
      .FormFields("Text2").Result = DateAdd("ww", -52, .FormFields("Text1").Result)
    End With


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by scorpdevil Sunday, April 3, 2011 11:29 PM
    Thursday, March 31, 2011 8:42 PM