Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Clear Button for Word forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pamela - 02 Jul 2007 19:58 GMT
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
Jay Freedman - 02 Jul 2007 20:44 GMT
> 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

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Pamela - 02 Jul 2007 21:44 GMT
Thanks - I guess I should have mentioned that I am using a template - which
is great, but my users like the 'clear button' we use on our pdf forms which
removes all data with a single click.

I'll give your suggestion a try - but we do use drop downs and check boxes,
so I guess that will reneder your 'alternative' useless.
Russ - 02 Jul 2007 23:00 GMT
Pamela,
Maybe you could include in your template a Menu item or toolbar button to
just close without saving the current partially data-loaded document and
reopen a fresh document based on your document with all new blank fields.
Wouldn't that accomplish the same thing?

> Thanks - I guess I should have mentioned that I am using a template - which
> is great, but my users like the 'clear button' we use on our pdf forms which
> removes all data with a single click.
>
> I'll give your suggestion a try - but we do use drop downs and check boxes,
> so I guess that will reneder your 'alternative' useless.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 02 Jul 2007 23:06 GMT
Correct inline below.

> Pamela,
> Maybe you could include in your template a Menu item or toolbar button to
> just close without saving the current partially data-loaded document and
> reopen a fresh document based on your document with all new blank fields.

That should read "fresh document based on your template"

> Wouldn't that accomplish the same thing?
>
[quoted text clipped - 4 lines]
>> I'll give your suggestion a try - but we do use drop downs and check boxes,
>> so I guess that will reneder your 'alternative' useless.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Pamela - 02 Jul 2007 23:16 GMT
Another good thought - if I was still using 2003 I would know how to do that.

Do you know how with 2007?
Russ - 02 Jul 2007 23:27 GMT
Pamela,
I haven't had the 'pleasure' of using Word2007.

> Another good thought - if I was still using 2003 I would know how to do that.
>
> Do you know how with 2007?

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Doug Robbins - Word MVP - 03 Jul 2007 03:32 GMT
I would suggest that you use a userform instead of a protected document with
formfields.

See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Another good thought - if I was still using 2003 I would know how to do
> that.
>
> Do you know how with 2007?
Jay Freedman - 03 Jul 2007 00:59 GMT
>Thanks - I guess I should have mentioned that I am using a template - which
>is great, but my users like the 'clear button' we use on our pdf forms which
>removes all data with a single click.
>
>I'll give your suggestion a try - but we do use drop downs and check boxes,
>so I guess that will reneder your 'alternative' useless.

No, it isn't useless, it's just written for the simplest case. To
handle all three kinds of fields, change the macro to

Sub ClearFields()
   Dim fld As FormField
   For Each fld In ActiveDocument.FormFields
       If fld.Type = wdFieldFormTextInput Then
           fld.Result = ""
       ElseIf fld.Type = wdFieldFormCheckBox Then
           fld.CheckBox.Value = False
       ElseIf fld.Type = wdFieldFormDropDown Then
           fld.DropDown.Value = 1
       End If
   Next
End Sub

Also, Russ's idea about a toolbar button is good. For Word 2007, put
the button on the Quick Access Toolbar -- click the down arrow at the
end of the bar, choose 'Customize the Quick Access Toolbar', select
the Macros group in the dialog, and add your macro to the list on the
right. You can also choose an icon for the button (that's allowed only
for macros, not for other kinds of commands).

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.