Consulting

Results 1 to 9 of 9

Thread: Dependent Drop Down Lists in Word

  1. #1

    Dependent Drop Down Lists in Word

    Hello,

    I'm creating a personal information form in Word and I need to have a drop down menus with 11 different South American Countries, once one is selected the other menus will automatically populated with the National ID's for that country.

    Ex. Someone selects 'MEXICO' in the first menu,

    The other menus will list "RFC" "IMSS" and "CURP". I intend to put a text box next to each menu so people can enter the proper IDs.

    Can someone please help with the code for this? I've been working on this for weeks now without an answer

    Thanks!!

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    See, for example:

    Dependent Dropdown Content Controls
    http://www.msofficeforums.com/word-v...html#post77762

    Hierarchical Dropdown Content Controls
    http://www.msofficeforums.com/word-v...html#post94603
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Thank you for your response, Macropod!

    I did as suggested, however, when I click on an item in the drop down, it deletes the suggestion.
    Can you please advise?
    Attached Files Attached Files

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Perhaps:
    Option Explicit
    Dim StrOption As String
    Private Sub Document_ContentControlOnEnter(ByVal CCtrl As ContentControl)
    StrOption = CCtrl.Range.Text
    End Sub
    Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
    Application.ScreenUpdating = False
    Dim i As Long, j As Long, StrID As String, StrAdd As String
    With CCtrl
      If .Title = "Pais" Then
        If StrOption = .Range.Text Then Exit Sub
        Select Case .Range.Text
          Case "Argentina": StrID = "DNI,CUIL": StrAdd = ""
          Case "Chile": StrID = "Cedula de Identidad": StrAdd = "Fonasa o Isapre,Monto UF Plan de Isapre"
          Case "Colombia": StrID = "Cedula de Identidad": StrAdd = "EPS,ARL,AFP,CCF"
          Case "Cost Rica": StrID = "Cedula de Identidad,NSS": StrAdd = ""
          Case "El Salvador": StrID = "DUI,NSS": StrAdd = ""
          Case "Guatemala": StrID = "DPI,NSS": StrAdd = ""
          Case "Honduras": StrID = "Cedula de Identidad": StrAdd = ""
          Case "Mexico": StrID = "CURP,RFC,IMSS": StrAdd = ""
          Case "Nicaragua": StrID = "Cedula de Identidad,NSS": StrAdd = ""
          Case "Peru": StrID = "DNI": StrAdd = "AFP"
          Case "Uruguay": StrID = "Cedula de Identidad": StrAdd = ""
          Case Else
            .Type = wdContentControlText
            .Range.Text = ""
            .Type = wdContentControlDropdownList
            StrID = "": StrAdd = ""
        End Select
        With ActiveDocument
          For i = 1 To .SelectContentControlsByTitle("ID").Count
            With .SelectContentControlsByTitle("ID")(i)
              .DropdownListEntries.Clear
              .Type = wdContentControlText
              .Range.Text = ""
              .Type = wdContentControlDropdownList
              For j = 0 To UBound(Split(StrID, ","))
                .DropdownListEntries.Add Split(StrID, ",")(j)
              Next
            End With
          Next
          For i = 1 To .SelectContentControlsByTitle("Addicionales").Count
            With .SelectContentControlsByTitle("Addicionales")(i)
              .DropdownListEntries.Clear
              .Type = wdContentControlText
              .Range.Text = ""
              .Type = wdContentControlDropdownList
              For j = 0 To UBound(Split(StrAdd, ","))
                .DropdownListEntries.Add Split(StrAdd, ",")(j)
              Next
            End With
          Next
        End With
      End If
    End With
    Application.ScreenUpdating = True
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    THIS WORKED!!! Thank you!

    I do have an additional question... is there a way to edit the design of the drop down so it is not so plain?
    When I hit design mode, a blue oval pops up without the drop down ability.

    Would you know how to change that?

    Thanks again!

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    About all you can do is apply the same kind of formatting that you could apply to content more generally. You might even put them in table cells with fancy borders.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    So I put in the code to the actual document I'm working on... For some reason when you do select a country and an ID the font becomes double the size

    Then the additional Id's are no longer updating and stay with only the Colombia additional ID info.

    I'm hoping this is the last time I bug you, thank you so much!!!
    Attached Files Attached Files

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by lgsikaffy View Post
    So I put in the code to the actual document I'm working on... For some reason when you do select a country and an ID the font becomes double the size

    That's because the output adopts the underlying formatting of the range it's attached to, which is 20pt Calibri.

    Quote Originally Posted by lgsikaffy View Post
    Then the additional Id's are no longer updating and stay with only the Colombia additional ID info.
    Actually that's not happening at all - the Columbia info is already there. The real problem is that the content controls are titled 'Adicionales', but the macro is looking for content controls titled 'Addicionales' (as per your previous attachment)...
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #9
    Quote Originally Posted by macropod View Post
    That's because the output adopts the underlying formatting of the range it's attached to, which is 20pt Calibri.[/FONT][/COLOR]
    [COLOR=#222222][FONT=Verdana]
    Actually that's not happening at all - the Columbia info is already there. The real problem is that the content controls are titled 'Adicionales', but the macro is looking for content controls titled 'Addicionales' (as per your previous attachment)...

    Thank you so much for your assistance! This totally worked!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •