Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word form - table of contents

Status
Not open for further replies.

furtivevole

Technical User
Jun 21, 2001
84
GB
I have a Word 97 document, in whcih the majority of sections are protected and contain form fields including text, drop-down and check box fields. Occasionally the doc may need to be unprotected either by self or by users, one reason being to refresh the table of contents.

I've already implemented the code given in MSKB 181108 (its equivalent for WD2000 is 191028) to retain field content when the doc is un/re-protected, which seems to work OK. The problem comes if the document is selected for refreshing the ToC. While data in the drop-down and check box fields are retained, everything in the freeform text fields is lost.

Does anyone have a solution to this?

Thanks, Linnet
 
Lock the text form fields before protecting the form:
Select the field
Press CTRL+F11

The locked text fields will retain their text and will function as usual while the form is being filled out in protected mode.

This preserves only text fields. Since you have already implemented MSKB 181108, I don't know (haven't tested) if the following statement from MS holds true: A calculation field may no longer be updated and will maintain the current value until unlocked, even if it is printed or if a macro is run to update it.
 
Unfortunately this is a non-starter. There are many individual fields to lock, and the doc has to be unprotected to do a select all.

It is the (Ctrl-A) select all that upsets the ToC refresh. From the investigations I've done subsequently, it seems that it's possibly achievable by intercepting the UpdateFields macro. But I'm getting out of my depth here, and havn't got much time to go into this further.

Interestingly an <f9> directly onto the ToC seems to do the refresh while preserving the field contents.

Thanks for the suggestion anyway.
 
Sorry, I assumed you were either clicking once either (1) anywhere in the TOC or (2) in the left margin of the TOC, before pressing <F9>.
 
I am not sure what differences in Word 97 there are re: VBA. However, this works with Word 2002.

Essentially: you put a bookmark right before the ToC (in this case it is called MyToC. This assumes there is no password. It also locks all fields before it does anything. You put this macro as the exiting macro on the LAST formfield in the protected area. When the user Tabs out of the last field the macro unprotects the doc, goes to the ToC and updates it, then protects the doc again.

Sub UpdateToC()
Dim aDoc As Document
Dim aField as FormField
Set aDoc = ActiveDocument
For Each aField In aDoc.FormFields
aField.Select
Selection.Fields.Locked = True
Next
If aDoc.ProtectionType <> wdNoProtection Then
aDoc.Unprotect Password:=""
End If
Selection.GoTo What:=wdGoToBookmark, Name:="MyToC"
With aDoc.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
aDoc.TablesOfContents(1).Update
adoct.Protect wdAllowOnlyFormFields, Password:=""
Set aDoc = Nothing
End Sub

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top