Calculated field in MS word base on another date field

LadyHagood
LadyHagood used Ask the Experts™
on
Hi All,
I'm using MS Word 2010 need to add a date field (Report_Due_Date) that is calculated to greater than another date field (Report Generation Date).  Need to automatically run on document open.

Any ideas?

Thank you!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
GrahamSkanRetired
Top Expert 2012

Commented:
What sort of field? If you mean a Word field, then you should be aware that while arithmetic data calculation is available, it is very difficult to do it with dates. VBA calculation is much easier, but some users consider VBA too difficult to make secure.

How much greater do you need the second field to be?

I suggest that you post a non-confidential example document.

Author

Commented:
Yes a word field.  VBA calculation is fine the security is not a major concern for this particular usage.  Second field is 30 days greater than the first.
Retired
Top Expert 2012
Commented:
You will need a macro like this in the document's ThisDocument code module.
Option Explicit


Private Sub Document_Open()
    Dim rng2 As Range
    Dim dt1 As Date
    Dim dt2 As Date
    
    dt1 = ThisDocument.Fields(1).Result
    dt2 = DateAdd("d", 30, dt1)
    
    Set rng2 = ThisDocument.Bookmarks("Date2").Range
    rng2.Text = Format(dt2, "dd/MM/yyyy")
    ThisDocument.Bookmarks.Add "Date2", rng2
End Sub

Open in new window

I have attached a sample document. The second date is not a Word Field, but is shown in a bookmarked location.
DateDemo.docm
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: GrahamSkan (https:#a42390898)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

MacroShadow
Experts-Exchange Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial