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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clearing Text and Check Boxes in a Word doc

Status
Not open for further replies.

siobhanh

Technical User
Oct 2, 2009
5
US
Is there a way to clear all the fields in a document. Being a novice, so far i could only come up with setting each field's value individually to blank but, there are a lot of them.
Thank you.
 
If these are formfields:
Code:
Sub ClearAllFormFields_A()
Dim oFF As FormField
For Each oFF In ActiveDocument.FormFields
 [COLOR=red]  ' if checkbox make it unchecked[/color red]
   If oFF.Type = wdFieldFormCheckBox Then
      oFF.Result = False
   End If
 [COLOR=red]  ' if textbox make it empty[/color red]
   If oFF.Type = wdFieldFormTextInput Then
      oFF.Result = ""
   End If
Next
End Sub

[COLOR=red]OR..........[/color red]
Sub ClearAllFormFields_B()
Dim oFF As FormField
For Each oFF In ActiveDocument.FormFields
   Select Case oFF.Type
      Case 71 [COLOR=red]' this is wdFieldFormCheckBox[/color red]
         oFF.Result = False
      Case 70 [COLOR=red] '  this is wdFieldFormTextInput[/color red]
         oFF.Result = ""
   End Select
Next
End Sub
Both versions do the same thing, although technically speaking, version _B is the better one. Why? Because it uses ONE Select Case instruction, as opposed to TWO If...Then instructions.


If these are ActiveX controls (from the Controls toolbar rather than the Forms toolbar), then different code is required.

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 
Gerry,
I'm sorry it took me so long to thank you for your response. I got involved with something else and forgot about this.
I am back to working on it and realize that I am using the Controls toolbar. If you don't mind, could you let me know if i can still clear all fields?
Fortunately, as you may have guessed I don't have a tight deadline on this.

Thank you so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top