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 / May 2006

Tip: Looking for answers? Try searching our database.

Clear All Form Fields?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TomorrowsMan - 04 May 2006 20:29 GMT
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
Helmut Weber - 04 May 2006 20:43 GMT
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
Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

TomorrowsMan - 05 May 2006 15:18 GMT
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
Doug Robbins - Word MVP - 05 May 2006 19:22 GMT
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.

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

> Thank you so much!
>
[quoted text clipped - 6 lines]
>
> TMan
Helmut Weber - 05 May 2006 20:24 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
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.