# MS Word - label text computed based on drop down



## KGee (Nov 23, 2009)

I'm creating a form with several drop-down list boxes and I want to add a "helper" field for each. I was thinking of a label that would display certain information based on the option selected in the list box.

For example, say my drop-down has choices of A, B and C. If A is selected, I want the text in the label field to read "For option A you need to blah blah blah", likewise the same setup for the remaining choices. If no selection is made, I want the label text to be blank.

I can set the code up the way I want using a select case statement, but don't know where to insert the code. I see a "click" option for the label field, but not for the drop-down and can't find an "on-change" event or similar for the document itself.

Is there another way to do this?

Thanks - Kevin


----------



## KGee (Nov 23, 2009)

I set up a macro for each of the drop-down boxes using a select case statement and have it set to run on entry/exit, but the label text is not being updated. What I have is listed below where "myBox1" is the bookmark name for the first drop-down and "lblBox1" is the name of the label I want to associate with the first drop-down box.


```
tmpText = myBox1
 
    Select Case tmpText
        Case Is = "A"
            lblBox1 = "A option selected"
        Case Is = "B"
            lblBox1 = "B option selected"
        Case Is = "C"
            lblBox1 = "C option selected"
        Case Else
            lblBox1 = "Nothing selected"
    End Select
```
 
Thanks - Kevin


----------



## tuiajdf (Nov 25, 2009)

okay, I agree I can set the code up the way I want using a select case statement, but don't know where to insert the code. I see a "click" option for the label field, but not for the drop-down and can't find an "on-change" event or similar for the document itself.


----------



## Macropod (Nov 26, 2009)

Hi Kevin,

There's no dropdown formfield selection event you can use to trigger the kind of display you're after.

If you specify the following macro as the 'on exit' macro for the formfield, selecting an option, then exiting the formfield will update the formfield's help text (which you can access by selecting the formfield and pressing F1). Personally, I don't see this being very useful, since you must exit the formfield before you can go back to it and see the help text for the chosen option.

```
Sub FF_Help()
Dim StrHlp As String
With ActiveDocument.FormFields("DropDown1")
  .OwnHelp = True
  Select Case .Result
    Case "A": StrHlp = "Option A selected"
    Case "B": StrHlp = "Option B selected"
    Case "C": StrHlp = "Option C selected"
    Case Else: StrHlp = ""
  End Select
  .HelpText = StrHlp
End With
End Sub
```
 A variation on the theme would be to have, say, an IF field that displays the help text - that way you would't need to re-access the formfield and press F1. Such a field might be coded as:

```
{IF{REF DropDown1}= "A" "Option A selected" {IF{REF DropDown1}= "B" "Option B selected" {IF{REF DropDown1}= "C" "Option C selected"}}}
```
or

```
{IF{REF DropDown1}= "A" "Option A selected"}{IF{REF DropDown1}= "B" "Option B selected"}{IF{REF DropDown1}= "C" "Option C selected"}
```
Such a solution requires no vba - just a bit of field coding with the 'calculate on exit' property set for the dropdown. It still doesn't get over the problem that the help text doesn't display until AFTER you've updated & exited the dropdown, however.

The best approach might be to have a field that's coded to show the help _until_ a dropdown option has been chosen. For example:

```
{IF{REF DropDown1}= "" "Help Text for A¶
Help Text for B¶
Help Text for C¶"}
```
With this approach, the help text will remain hidden while any of your A/B/C options is current. Re-displaying the text is as simple as selecting the 'blank' option and exiting the formfield.

Note: The field brace pairs (ie '{ }') for the above examples are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message.


----------

