Placing calculated dates in a Word document

How to insert a field in a Word document that calculates dates.

Q:  George Forsythe writes:  “I want to insert a field in a Word document that calculates Tomorrow’s date. It would be even better if I could make it Next Weekday’s date. There seems to be no intuitively obvious way to do this.”

A:  This is easy enough when writing data to a Word document from Access; just use DateAdd(“d”, 1, Date()) to get tomorrow’s date, and write it to a Word doc property (I like to use Text properties and format the results with field switches, to avoid having to enter a default value).

For the next weekday, use code like the following:

Public Function NextWeekday(dteTest) As Date

 

   Dim dteTestDate As Date

   Dim n As Integer

 

   dteTestDate = dteTest

   If Weekday(dteTestDate) <> vbSaturday And Weekday(dteTestDate) _

      <> vbSunday Then

      NextWeekday = dteTestDate

   Else

      For n = 1 To 7

      dteTestDate = DateAdd(“d”, n, dteTest)

      If Weekday(dteTestDate) <> vbSaturday And _

         Weekday(dteTestDate) <> vbSunday Then

         NextWeekday = dteTestDate

         Exit Function

      End If

      Next n

 

   End If

 

End Function