On Open event to clear all form fields or not..

W

Worsty

I have the following code in my OnOpen event of my word document
form. As long as you answer "Yes" to the msg box the code works fine,
but if you say no, then it exposes rows in my form that contain VBA
buttons and radio buttons.

Can anyone help me out with how to fix this?

Thanks so much....

Here is the code:

Dim myFormField As FormField
Dim aDoc As Document
Dim response
Dim msg As String


Set aDoc = ActiveDocument
msg = "Do you want to clear all FormField results?"
response = MsgBox(msg, vbYesNo)
If response = vbYes Then
For Each myFormField In aDoc.FormFields()
Select Case myFormField.Type
Case 70 ' text
' checks to see if there is default text
' if yes, removes user inout and
' reverts to default; if no, removes user input
If myFormField.TextInput.Default <> "" Then
myFormField.Result = myFormField.TextInput.Default
Else
myFormField.Result = ""
End If
Case 71 ' check
myFormField.Result = False
Case 83 ' dropdown
myFormField.DropDown.Value = 1

End Select
 
F

Fumei2 via OfficeKB.com

" if you say no, then it exposes rows in my form that contain VBA
buttons and radio buttons."

Could elaborate on this? As is, I see no connection. Where these hidden in
some way? What do you mean "expose"?
 
G

Graham Mayor

While your syntax appears a tad awry - try the following - I too don't see
the connection between your code and the hidden data.

Dim myFormField As FormField
Dim aDoc As Document
Dim response
Dim msg As String
Set aDoc = ActiveDocument
msg = "Do you want to clear all FormField results?"
response = MsgBox(msg, vbYesNo)
If response = vbYes Then
For Each myFormField In aDoc.FormFields()
Select Case myFormField.Type
Case 70 ' text
' checks to see if there is default text
' if yes, removes user inout and
' reverts to default; if no, removes user input
If myFormField.TextInput.Default <> "" Then
myFormField.Result = myFormField.TextInput.Default
Else
myFormField.Result = ""
End If
Case 71 ' check
myFormField.CheckBox.Value = 0
Case 83 ' dropdown (selects first item in list)
myFormField.DropDown.Value = 1
End Select
Next myFormField
End If


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
W

Worsty

While your syntax appears a tad awry - try the following - I too don't see
the connection between your code and the hidden data.

Dim myFormField As FormField
Dim aDoc As Document
Dim response
Dim msg As String
Set aDoc = ActiveDocument
msg = "Do you want to clear all FormField results?"
response = MsgBox(msg, vbYesNo)
If response = vbYes Then
    For Each myFormField In aDoc.FormFields()
        Select Case myFormField.Type
            Case 70  ' text
                ' checks to see if there is default text
                ' if yes, removes user inout and
                ' reverts to default; if no, removes userinput
                If myFormField.TextInput.Default <> "" Then
                    myFormField.Result = myFormField.TextInput.Default
                Else
                    myFormField.Result = ""
                End If
            Case 71  ' check
                myFormField.CheckBox.Value = 0
            Case 83   ' dropdown (selects first item in list)
                myFormField.DropDown.Value = 1
        End Select
    Next myFormField
End If

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>












- Show quoted text -

Thanks so much.....I'll work on this and get back to you.
 

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