MS Word - label text computed based on drop down

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
539
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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.

Code:
    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
 
Upvote 0
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.
 
Upvote 0
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.
Code:
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:
Code:
{IF{REF DropDown1}= "A" "Option A selected" {IF{REF DropDown1}= "B" "Option B selected" {IF{REF DropDown1}= "C" "Option C selected"}}}
or
Code:
{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:
Code:
{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.
 
Upvote 0

Forum statistics

Threads
1,225,464
Messages
6,185,140
Members
453,279
Latest member
MelissaOsborne

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top