are there restrictions with the name in the field (e.g. 2 words, or use of special caracters)?
Like Field A (Company Name) Field B (Director Name, like Jack Black).
As the left screenshot shown, you need to limit the choices in the second drop-down list based on the option in the first drop-down, how can you do? This article will show you method to create dependent drop-down lists in Word document.
The below VBA code can help you creating dependent drop-down lists in a Word document. Please follow the instruction step by step.
1. Firstly, you need to insert two drop-down lists in your Word document. Click Developer > Legacy Forms > Drop-Down Form Field. See screenshot:
2. Right click the first drop-down list (this drop-down list should be the parent one), and click Properties. See screenshot:
3. In the opening Drop-down Form Field Options dialog box, you need to:
3.1 Enter the category into the Drop-down item box and then click the Add button, repeat the operation until all categories are added to the Items in drop-down list box.
3.2 Enter ddfood into the Bookmark box.
3.3 Click the OK button. See screenshot:
4. Right click the second drop-down list, click Properties to open its Drop-down Form Field Options dialog box, and in the dialog, enter ddCategory into the Bookmark box and click the OK button. See screenshot:
5. Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
6. In the Microsoft Visual Basic for Applications window, click Insert > Module, then copy below VBA code into the Module window.
VBA code: Create dependent drop-down list in Word
Sub Populateddfood() 'Update by Extendoffice 2018/10/25 Dim xDirection As FormField Dim xState As FormField On Error Resume Next Set xDirection = ActiveDocument.FormFields("ddfood") Set xState = ActiveDocument.FormFields("ddCategory") If ((xDirection Is Nothing) Or (xState Is Nothing)) Then Exit Sub With xState.DropDown.ListEntries .Clear Select Case xDirection.Result Case "Fruit" .Add "Apple" .Add "Banana" .Add "Peach" .Add "Lychee" .Add "Watermelon" Case "Vegetable" .Add "Cabbage" .Add "Onion" Case "Meat" .Add "Pork" .Add "Beef" .Add "Mutton" End Select End With End Sub
1. In the code, please change items under each case as you need.
2. ddfood and ddCategory should match the Bookmark options you entered in the above two Drop-down Form Field Options dialog boxes.
7. Save the code and go back to the document.
8. Right click the first drop-down list and click Properties to open the Drop-down Form Field Options dialog box. In the dialog box, please select the above Macro name (here is Popolateddfood) from the Exit drop-down list, and then click the OK button.
9. Now click Developer > Restrict Editing as below screenshot shown.
10. In the Restrict Editing pane , you need to:
10.1), Check the Allow only this type of editing in the document box;
10.2) Select Filling in forms option from the drop-down list;
10.3) Click the Yes, Start Enforcing Protection button;
10.4) In the Start Enforcing Protection dialog, enter the password and click the OK button. See screenshot:
Now the dependent drop-down lists are created. When selecting Fruit from the first drop-down list, only the fruit categories can be selected in the second one.