Conditional Text Display

C

cfp76

I have searched the forums and have not come up with anything tha
matches my need.

I am creating a quick little form (meant to be simple, don't ask). On i
are a series of questions I am using drop down lists for (simple Yes/N
questions). Some of the questions should ONLY appear if a previous bo
captures the Yes or No value.

For example:
When the user first opens the form, they see 1 question:

Do you like dogs? (drop down menu here)

Based on their selection, if the selection is yes, then it should sho
the next question Do you like big dogs? (another drop down menu here fo
answer)

I can add the field to the IF statement, but I'm having trouble gettin
the value from the drop down from the first question. I assigned it as
bookmark but that doesn't seem to be working (I probably did it wron
GRRR)

Another issue is that the text does not refresh automatically. I need i
so that as soon as the user selects Yes, the next question shows up.
am not working with people who use Word alot so I cannot ask them t
refresh all the time. That's not even an option.

Any help would be appreciated
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
580
Reaction score
50
Hi cfp76,

You can't make a formfield appear conditionally via an IF field. You need to programmatically add/delete the formfield, along with any associated content. For the general principles, see the following code (from a solution I posted in another forum), which is designed for an ‘On Exit’ macro attached to a checkbox Formfield with the bookmark name "Check1". If the CheckBox is checked, a (previously) bookmarked range named "MyBkMrk" is populated with a string and two Formfields, the first of which is selected; otherwise the bookmarked range is cleared. If the user tabs through the already-checked CheckBox, the bookmarked range is preserved (along with the Formfield contents).
Code:
Sub ShowHide()
Dim BmkNm As String, NewTxt As String, BmkRng As Range, FFld As Formfield
BmkNm = "MyBkMrk"
NewTxt = "The pay rate is || per hour for ** hours."
Application.ScreenUpdating = False
With ActiveDocument
  If .Bookmarks.Exists(BmkNm) Then
    .Unprotect
    Set BmkRng = .Bookmarks(BmkNm).Range
    If .Formfields("Check1").Result = 0 Then
      NewTxt = ""
      For Each FFld In BmkRng.Formfields
        FFld.Delete
      Next
    ElseIf BmkRng.Text <> "" Then
      .Protect Type:=wdAllowOnlyFormfields, noreset:=True
      End
    End If
    BmkRng.Text = NewTxt
    .Bookmarks.Add BmkNm, BmkRng
    If NewTxt <> "" Then
      BmkRng.Select
      With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "||"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute
      End With
      Set FFld = ActiveDocument.Formfields _
        .Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With FFld
        .Name = "Text98"
        .TextInput.EditType Type:=wdNumberText, Default:="", Format:="$#,##0.00"
        .TextInput.Width = 8
        .Result = "$0.00"
      End With
      BmkRng.Select
      With Selection.Find
        .Text = "**"
        .Execute
      End With
      Set FFld = ActiveDocument.Formfields _
        .Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
      With FFld
        .Name = "Text99"
        .TextInput.EditType Type:=wdNumberText, Default:="", Format:="0"
        .TextInput.Width = 2
        .Result = "0"
      End With
      .Bookmarks("Text98").Range.Select
    End If
    .Protect Type:=wdAllowOnlyFormfields, noreset:=True
  End If
End With
Set BmkRng = Nothing
Application.ScreenUpdating = True
End Sub
 

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