Pamela said:
I need a button that will clear data added to form fields in a
protected form - so it is ready to reuse. I also need to have this
button not print when document is printed.
Any suggestions? Thanks
The main suggestion is to create the form as a template instead of a
document, and use File > New to create a new document based on that template
for each use. That way the fields will always start out empty, and you don't
need a button.
The alternative is fairly nasty. Create a macro like this (assuming all form
fields are text, not dropdowns or checkboxes):
Sub ClearFields()
Dim fld As FormField
For Each fld In ActiveDocument.FormFields
fld.Result = ""
Next
End Sub
Insert a macrobutton field,
{MacroButton ClearFields Double-click here to clear fields}
(see
http://www.word.mvps.org/FAQs/TblsFldsFms/UsingMacroButton.htm).
To prevent the macrobutton field from printing, surround it with a
bookmark -- say you name it ClearButton. Then write two macros to intercept
the File > Print menu command and the Print button on the toolbar
(
http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm):
Sub FilePrint()
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
.Bookmarks("ClearButton").Range.Font.Color = wdColorWhite
Dialogs(wdDialogFilePrint).Show
.Bookmarks("ClearButton").Range.Font.Color = wdColorAutomatic
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
End Sub
Sub FilePrintDefault()
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
.Bookmarks("ClearButton").Range.Font.Color = wdColorWhite
.PrintOut Background:=False
.Bookmarks("ClearButton").Range.Font.Color = wdColorAutomatic
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.