I am very new to VBA and I am trying to create an online form in which
several dates auto fill when the form is opened. I would like to insert a
date that is 7 days prior to the current date into a form field with a
bookmark name of OnsetDate. I created the following macro with no success:
Sub OnsetDate()
Dim OneW as Date
OneW=Format(DateAdd("d",-7,Date), "mm dd yyyy"
Selection.InsertBefore OneW
End Sub
Any suggestions?
TIA
Nicole
Nicole.Krzywonski@no.spam.dshs.state.tx.us
Greg - 13 Apr 2005 03:26 GMT
Nicole,
To fire a macro when a document opens you need to use a document event
name. To set the value of a formfield use something like:
Sub Document_Open()
Dim OneW As Date
OneW = Format(DateAdd("d", -7, Date), "mm dd yyyy")
ActiveDocument.FormFields("OneW").Result = OneW
End Sub