Autofill a form field when document opens

  • Thread starter Nicole Kelly-Krzywonski
  • Start date
N

Nicole Kelly-Krzywonski

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
(e-mail address removed)
 
G

Greg

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
 

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