How do I auto increment a date in a form?

G

Greg Madigan

I have a daily form that I would like to print off for several days in
advance but I do not know how to enter a date and then get it to increment
the date on each new copy. It seems like there should be a way to create a
marco to do this but I am weak on macros. Can anyone point me in the
direction of a possible solution?

Thank you.
 
B

Brian

This works in Excel...

Private Sub ChangeDate()
Dim myDate As Date
Dim myNewDate As Date

myDate = Now
myNewDate = DayIncrement(myDate, 1)

End Sub

Private Function DayIncrement(sDate As Date, incBy As Integer)
DayIncrement = sDate + Day(incBy)
End Function
 
D

Doug Robbins - Word MVP

Insert a Docvariable field { DOCVARIABLE "varDate"} in the document where
you want the date to appear and then run the following macro:

Dim i As Long, j As Long
j = InputBox("Enter the number of days for which you want to print the
form", "Form Maker", 1)
With ActiveDocument
For i = 0 To j - 1
.Variables("varDate").Value = Format(DateAdd("d", i, Date), "MMMM d,
yyyy")
.Fields.Update
.PrintOut
Next
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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

Top