Text box filled based on dropdown selection

Roro_6768 Posted messages 2 Status Member -  
 Roro_6768 -
Hello,

This conversation already exists for Excel, but I would like to do it in Word 2016.

The idea is that I have a dropdown list with several choices and later in the text, I have several text boxes that I would like to fill automatically based on what was selected in the dropdown list.

If I choose "choice 1" from the dropdown list, I want all the text boxes to have "text 1"
If I choose "choice 2" from the dropdown list, I want all the text boxes to have "text 2"
And so on.

Thank you in advance for your response,
Roro

2 answers

  1. m@rina Posted messages 27560 Registration date   Status Moderator Last intervention   11 562
     
    Hello,

    We first need to know what type of dropdown list and text area you are using. There are at least three types. Explanations here:
    https://faqword.com/index.php/word/formulaires-controles/911-le-point-sur-les-outils-de-formulaires

    m@rina

    0
    1. Roro
       
      I use dropdown list content control, but I can use something else if needed.
      I just want to avoid wasting time clicking on each list.

      Roro
      0
  2. m@rina Posted messages 27560 Registration date   Status Moderator Last intervention   11 562
     
    Hello,

    Assuming that the control tag name is "tag1", assuming that the text box is named "zdt1", here is a macro that will trigger upon exiting the dropdown list:

    Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
    If CC.Tag = "tag1" Then
    montexte = CC.Range.Text
    ActiveDocument.Shapes("zdt1").TextFrame.TextRange.Text = montexte
    End If
    End Sub


    I explain here:
    https://faqword.com/index.php/word/formulaires-controles/902

    Of course, if you have multiple text boxes, you can loop through them or name each one. It all depends on your document.

    m@rina

    --
    There is no need to ask your questions privately. I do not respond to them.
    0
    1. Roro_6768 Posted messages 2 Status Member
       
      Hello,

      After naming the tag and the text area, I don't see where to execute my macro in Word; I might not have the right type of dropdown list to trigger my macro on output.

      I also don't know how to specify in the macro that I have multiple texts. I have 3 different texts in my dropdown list
      (text1 in the list --> text 1 in the area;
      text 2 in the list --> text 2 in the area;
      text3 in the list --> text 3 in the area)
      and unfortunately, I don't know enough to complete the code.

      Thanks again for your help.

      Roro
      0
    2. m@rina Posted messages 27560 Registration date   Status Moderator Last intervention   11 562
       
      Good evening,

      "I can't see where to run my macro in Word
      I think you haven't read or even looked at the link I gave you...

      Regarding the 3 different texts, the macro doesn't care, since it processes the result, that is, the choice you made from the list.
      0
    3. Roro_6768
       
      Hello,

      I only read the link but it's my first time using macros in Word, so I'm a bit lost.

      When you say "at the output of the content control," do you mean that when I make a selection in my dropdown list, it should automatically display in the text box? Because if that's the case, I haven't managed to get the code to work. I opened the Microsoft Visual Basic window where I copied your code, being careful to change the name of my dropdown list tag as well as the bookmark of my text box. I saved it and now I'm not sure what I'm supposed to do.

      Also, maybe I expressed myself poorly; the text in the dropdown list isn't necessarily identical to the text I want in the text boxes.

      Roro
      0