Re: Form Fields Reset by macropod
macropod
Tue Jul 15 06:41:22 PDT 2008
Hi Eric,
The formfields are being reset because the code doesn't look to see what type of field it is beforehand.
Provided you set your formfield properties to set a bookmark value and 'calculate on exit', any REF fields & formfields dependent on
them should update automatically. That would only leave fields like Tables Of Contents, Authorities and Figures, which would only
need updating if the data going into the formfields is liable to change a heading's text or which page a given heading/reference
appears on. For that you could use a sub like:
Sub RefreshDocTables()
Dim TOC As TableOfContents ' Table of Contents Object
Dim TOA As TableOfAuthorities ' Table of Authorities Object
Dim TOF As TableOfFigures ' Table of Figures Object
Dim pRange As Word.Range ' Word Range Object
Dim strPwd As String ' Password variable
Dim pState As Boolean ' Protection State
With ActiveDocument
If .ProtectionType = wdAllowOnlyFormFields Then
pState = True
strPwd = InputBox("Please input the Password", "Document Protected for Forms")
.Unprotect (strPwd)
End If
' The following routines update the TOC, TOA or TOF contents.
' Loop through Tables Of Contents and update
For Each TOC In .TablesOfContents
TOC.Update
Next
' Loop through Tables Of Authorities and update
For Each TOA In .TablesOfAuthorities
TOA.Update
Next
' Loop through Tables Of Figures and update
For Each TOF In .TablesOfFigures
TOF.Update
Next
If pState = True Then .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=strPwd
pState = False
End With
End Sub
--
Cheers
macropod
[MVP - Microsoft Word]
"Eric" <Eric@discussions.microsoft.com> wrote in message news:FE02A5F1-E6F1-47A1-A478-F9F27FCF91AB@microsoft.com...
>I have a template with several Form Fields, REF Text and a TOC. I have a
> macro that updates all Fields on the tool bar that allows users to update
> fields when the Doc is protected. But the Form fields get reset when the
> user uses this macro. Please help.
>
> Sub UpdateFields()
>
> '
> '
> Dim oStory As Range
> For Each oStory In ActiveDocument.StoryRanges
> oStory.Fields.Update
> If oStory.StoryType <> wdMainTextStory Then
> While Not (oStory.NextStoryRange Is Nothing)
> Set oStory = oStory.NextStoryRange
> oStory.Fields.Update
> Wend
> End If
> Next oStory
> Set oStory = Nothing
> End Sub
> --
>
> Thanks
> Eric the Rookie