Updating dates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Need help on updating dates.
Have inserted date field as orginal creation date. Would like to have 2 more fields that link to the first date
that add 6 months in the 2nd field and 6 months and 1 day in the 3rd field
Hope someone has idea on how to do this

Thanks in advance, Jimmy
 
Sadly, Word can't do arithmetic with dates in fields alone. It's trivial if
you know any VBA: the DateAdd() function does exactly what you need. You
could add an AutoNew macro that creates Document Properties for the +6
months and +1 day values; then use DocProperty fields to put those dates
into the document.


Jimmy said:
Need help on updating dates.
Have inserted date field as orginal creation date. Would like to have 2
more fields that link to the first date
 
Thanks, Jezebe
Where could i get info on how to do this , or an example, I've never used VB

Thanks, Jimmy
 
Hi Jimmy

Following is some code that will create two document properties holding
the dates you need. If you're not sure what to do with the macro, see
http://www.gmayor.dsl.pipex.com/installing_macro.htm and
http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm

Now, in your document where you want the date to appear, create a field
like { docproperty "6months" \@ "dddd, d MMMM yyyy" } and { docproperty
"6monthsPlusOneDay" \@ "dddd, d MMMM yyyy" }.

Note that you can't type the {} braces by hand. You must use ctrl-F9 and
type between the braces that Word inserts for you. Once you've typed the
field, use F9 to update it, or ctrl-a F9 to update all fields in the
document.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


Option Explicit

Sub AutoOpen()
'Shauna Kelly, 2 February 2004
'For microsoft.public.word.docmanagement

Dim dCreateDate As Date

'Delete any existing document properties
On Error Resume Next
ActiveDocument.CustomDocumentProperties("6months").Delete
ActiveDocument.CustomDocumentProperties("6monthsPlusOneDay").Delete
On Error GoTo 0

'Calculate the document creation date
dCreateDate =
ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeCreated)

'Create a document property for 6 months after creation date
ActiveDocument.CustomDocumentProperties.Add _
Name:="6months", _
LinkToContent:=False, _
Type:=msoPropertyTypeDate, _
Value:=DateAdd(Interval:="m", Number:=6, Date:=dCreateDate)

'Create a document property for 6 months + 1 day after creation date
ActiveDocument.CustomDocumentProperties.Add _
Name:="6monthsPlusOneDay", _
LinkToContent:=False, _
Type:=msoPropertyTypeDate, _
Value:=DateAdd(Interval:="d", Number:=1,
Date:=ActiveDocument.CustomDocumentProperties("6months"))

End Sub
 
Thanks,
I'll give the links a read and try to go from there

Jimm

----- Shauna Kelly wrote: ----

Hi Jimm

Following is some code that will create two document properties holdin
the dates you need. If you're not sure what to do with the macro, se
http://www.gmayor.dsl.pipex.com/installing_macro.htm an
http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.ht

Now, in your document where you want the date to appear, create a fiel
like { docproperty "6months" \@ "dddd, d MMMM yyyy" } and { docpropert
"6monthsPlusOneDay" \@ "dddd, d MMMM yyyy" }

Note that you can't type the {} braces by hand. You must use ctrl-F9 an
type between the braces that Word inserts for you. Once you've typed th
field, use F9 to update it, or ctrl-a F9 to update all fields in th
document

Hope this helps

Shauna Kelly. Microsoft MVP
http://www.shaunakelly.com/wor


Option Explici

Sub AutoOpen(
'Shauna Kelly, 2 February 200
'For microsoft.public.word.docmanagemen

Dim dCreateDate As Dat

'Delete any existing document propertie
On Error Resume Nex
ActiveDocument.CustomDocumentProperties("6months").Delet
ActiveDocument.CustomDocumentProperties("6monthsPlusOneDay").Delet
On Error GoTo

'Calculate the document creation dat
dCreateDate
ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeCreated

'Create a document property for 6 months after creation dat
ActiveDocument.CustomDocumentProperties.Add
Name:="6months",
LinkToContent:=False,
Type:=msoPropertyTypeDate,
Value:=DateAdd(Interval:="m", Number:=6, Date:=dCreateDate

'Create a document property for 6 months + 1 day after creation dat
ActiveDocument.CustomDocumentProperties.Add
Name:="6monthsPlusOneDay",
LinkToContent:=False,
Type:=msoPropertyTypeDate,
Value:=DateAdd(Interval:="d", Number:=1
Date:=ActiveDocument.CustomDocumentProperties("6months")

End Su
 
See
http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=wrd&Number=249902.
This is a download containing the needed fields.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.


Jimmy said:
Need help on updating dates.
Have inserted date field as orginal creation date. Would like to have 2
more fields that link to the first date
 
Do anyone have a file that has these dates already in them where as I can copy and paste it into a file
Because I really can't determine the first, second, third, and etc. steps to take

----- Jezebel wrote: ----

Sadly, Word can't do arithmetic with dates in fields alone. It's trivial i
you know any VBA: the DateAdd() function does exactly what you need. Yo
could add an AutoNew macro that creates Document Properties for the +
months and +1 day values; then use DocProperty fields to put those date
into the document


Jimmy said:
Need help on updating dates
Have inserted date field as orginal creation date. Would like to have
more fields that link to the first dat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top