View Single Post
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

Seagull wrote:
I have created a protected form as a template, using dropdown fields,
etc. I want the date on which the form is used to fill automatically
and remain as this date, if reopened at a later date.

By using the current date field, the current day's date always
appears. By using the create date field, the date on which the form
was created appears. As the form is protected, I can't update the
field.

I think there may be some way to protect, unprotect and insert the
date and reprotect the form? Any suggestions?


You'll need two things: A macro in the template, and a MacroButton field and
a bookmark to launch it.

The macro should look like this (tweak the format string to the date format
you prefer, and add password handling if necessary):

Sub InsertCurrentDate()
Dim oRg As Range

With ActiveDocument
If .ProtectionType wdNoProtection Then
.Unprotect
End If

Set oRg = .Bookmarks("CurrentDate").Range
oRg.Text = Format(Date, "d MMMM yyyy")
.Bookmarks.Add Name:="CurrentDate", Range:=oRg

.Protect Type:=wdAllowOnlyFormFields
End With
End Sub

In the template, place a bookmark named CurrentDate where you want the date
to appear, and next to it place a macrobutton field with a field code like
this:

{ MacroButton InsertCurrentDate Double-click to insert date }

When you create a document based on the template, you can double-click the
macrobutton's text to insert the date at the bookmark. Since it's plain text
rather than a field, the date won't update unless you double-click the
macrobutton again.

As a variation, if you put the macrobutton field inside the bookmark, the
date can only be set once. The inserted text will wipe out the macrobutton
field, so the date becomes permanent.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org