Clear All Form Fields?

T

TomorrowsMan

Is it possible to assign vba to a commandbutton_click that would clear
form fields in a word document?

I have a word doc with many form fields, and I would like to have a
button that, when clicked, would clear just the form fields that have
numerical values (bookmarked num1, num2, etc.), but not all of the form
fields in the doc.

Cheers,

TMan
 
H

Helmut Weber

Hi,

like this:

Sub ClearNums()
Dim oFrm As FormField
For Each oFrm In ActiveDocument.FormFields
If Left(oFrm.Name, 3) = "Num" Then ' case sensitive !
oFrm.Result = ""
End If
Next
End Sub
--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
T

TomorrowsMan

Thank you so much!

One question; does the '3' in "If Left(oFrm.Name, 3)" refer to the
length of the character string?

Also, should this work even to reset dropdown menu selections?

Again, thanks!

TMan
 
D

Doug Robbins - Word MVP

Yes, that is what it does mean. I suggest however that you take a bit of
time and check the Visual Basic help file for the meaning of things. To get
context sensitive help, press F1 when the selection is immediately after the
item about which you want to know something. In this case after the t of
Left.

--
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
 
H

Helmut Weber

Hi TomorrowsMan,
Also, should this work even to reset dropdown menu selections?

Maybe you mean to reset the dropdown list,
so that the first item in the list is displayed,
instead of any other item the user may have selected.


Sub ClearNums2()
Dim oFrm As FormField
For Each oFrm In ActiveDocument.FormFields
If Left(oFrm.Name, 3) = "Num" Then ' case sensitive !
If oFrm.Type = wdFieldFormDropDown Then
oFrm.DropDown.Value = 1 ' < !
Else
oFrm.Result = ""
End If
End If
Next
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top