Link two dropdown menus

EC17 -  
m@rina Posted messages 27617 Registration date   Status Moderator Last intervention   -
Hello everyone,

I am trying to link two dropdown menus in a Word document but I can't find the solution.

Let me explain:

On page 1 of the document, I create a dropdown menu (let's call it "client" dropdown, for example).

On page 2 of the same document, I would like this "client" dropdown to appear and update every time I change my choice on page 1.

I hope I have expressed myself clearly enough ;-)

Thank you for your help.

2 answers

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

    First of all, I have a few questions:
    - What is your version of Word?
    - What type of dropdown menus (there are 3 kinds)?
    - If the choice is always made in the dropdown menu on page 1, why is there a dropdown menu on page 2? A link to the first menu's choice should be sufficient...

    m@rina

    --
    There’s no need to ask me your questions privately. I won't respond to them.
    0
    1. EC17
       
      Hello Marina,

      Thank you for your response.

      - I am using Microsoft Office 365, so I imagine it's the latest version of Word.

      - I use drop-down menus with content control. I write the content and leave the possibility to modify it.

      - Indeed, I may have expressed myself poorly, but that's what I'm looking for: I would like to create links between my drop-down menu on page 1 and a field on page 2 with the text I chose on page 1.

      Thank you for your help.
      0
  2. m@rina Posted messages 27617 Registration date   Status Moderator Last intervention   11 563
     
    Good evening,

    So, we need a macro that triggers when exiting the control. The challenge is to determine where we want to report the result of the dropdown list. In Word, unlike Excel, which works with "simple" references, it is always complicated.
    In fact, a location can be various things, such as
    - a specific location (number of paragraphs, words, characters, etc.)
    - an object that can be numbered, such as a table, a text box, a section...
    - a bookmark

    We easily use bookmarks. The issue is that they are volatile and can be easily deleted without realizing it.

    If this happens in a protected document, it's easier. So without knowing how or where you want to retrieve the text, without knowing if the document is protected, here is a macro that triggers when exiting the dropdown list:

    Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
    Dim B As String
    If CC.Tag = "ld" Then
    B = CC.Range.Text
    FillBookmark "my_bookmark", B
    End If
    End Sub

    Public Function FillBookmark(A As String, B As String)
    ' Fills bookmark A with text B without destroying A
    On Error GoTo exit
    Dim Place As Long
    Place = ActiveDocument.Bookmarks(A).Range.Start
    ActiveDocument.Bookmarks(A).Range.Text = B
    ActiveDocument.Bookmarks.Add Name:=A, Range:=ActiveDocument.Range(Place, Place + Len(B))
    exit:
    End Function


    For this example to work, you need to name the tag of your dropdown list "Id" and insert a bookmark at the location where you want to retrieve the text, which you will name "my_bookmark".

    I used the FillBookmark function to prevent the bookmark from being deleted (it would be by default) when you make another choice in the dropdown list. I explain here:
    https://faqword.com/index.php/word/gestion-des-macros/941-inserer-texte-via-macro-a-un-emplacement-avec-signet-sans-supprimer-le-signet

    m@rina

    0