PDA

View Full Version : [SOLVED:] Dependent Drop Down Lists in Word



lgsikaffy
04-13-2019, 12:01 PM
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!!

macropod
04-13-2019, 01:54 PM
See, for example:

Dependent Dropdown Content Controls
http://www.msofficeforums.com/word-vba/24661-help-cascading-dropdown-list.html#post77762

Hierarchical Dropdown Content Controls
http://www.msofficeforums.com/word-vba/29617-creating-reducing-drop-down-list.html#post94603

lgsikaffy
04-16-2019, 06:13 AM
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?

macropod
04-16-2019, 03:10 PM
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

lgsikaffy
04-16-2019, 08:05 PM
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!

macropod
04-16-2019, 08:16 PM
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.

lgsikaffy
04-16-2019, 08:50 PM
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 :banghead::banghead::banghead::banghead::banghead:

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!!!

macropod
04-16-2019, 09:09 PM
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.

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)...

lgsikaffy
04-17-2019, 06:23 AM
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!