Use "Value" Field from Drop-Down List Properties with a Combo Box Content Control

Copper Contributor

Hi There,

 

I am wanting to do something which should seem to be very basic but doesn't seem to work and am pulling my hair out. I am using a Combo Box Content Control drop down for users to select a persons initials, however in the drop down list I want to show the persons full name to save any confusion. 

 

For example in the drop down list I want the users to see "John Smith" or "Mary Jones" but when the user makes their selection I want only the initials to populate the field so "JS" or "MJ". 

 

RobertOliverNZ_0-1684804904371.png

 

I have tried using various Visual Basic modules I found online but all seem to throw up various issues and I'm not really a coder. Hoping someone has a simple fix for what seems to be such a simple thing that Word misleads you with.

 

Thanks in advance!

 

8 Replies

@RobertOliverNZ 

To achieve the desired functionality in Microsoft Word with a Combo Box Content Control, you can use a combination of the Display Name and Value properties. Here's a step-by-step guide:

  1. Open your Word document and go to the Developer tab. If you don't see the Developer tab in the ribbon, you may need to enable it first. You can do this by going to Word Options, selecting Customize Ribbon, and checking the box for Developer.

  2. Click on the Combo Box Content Control button in the Controls group to insert a combo box into your document.

  3. Right-click on the combo box and choose Properties from the context menu.

  4. In the Content Control Properties dialog box, go to the Drop-Down List Properties tab.

  5. Enter the full names (e.g., "John Smith", "Mary Jones") in the Display Name column and enter the corresponding initials (e.g., "JS", "MJ") in the Value column. Each entry should be in the same row.

  6. Click OK to close the Content Control Properties dialog box.

  7. Now, when you use the combo box, the user will see the full names in the drop-down list, but only the initials will be populated in the field when a selection is made.

If you want to retrieve the selected value (initials) from the combo box using VBA, you can use the following code:

Sub GetSelectedValue()
    Dim cc As ContentControl
    Set cc = ActiveDocument.SelectContentControlsByTitle("YourComboBoxTitle").Item(1)
    
    If cc.Type = wdContentControlComboBox Then
        Dim selectedValue As String
        selectedValue = cc.Range.Text
        ' Use the selectedValue as needed
    End If
End Sub

Replace "YourComboBoxTitle" with the title you have given to the combo box content control.

Remember to save your document as a macro-enabled (.docm) file if you want to use VBA code.

I hope this helps! 

Thanks for the reply @NikolinoDE 

 

I have followed your steps 1-7, as this is exactly how I thought it should work and had already tried this, however the field does not populate with the Value, only the Display Name. See screen shots below. I have also captured the version of Word I am using incase this may be effecting it. 

 

Any further ideas? 

 

Version: Microsoft® Word for Microsoft 365 MSO (Version 2304 Build 16.0.16327.20200) 64-bit

 

RobertOliverNZ_0-1684875596352.png

RobertOliverNZ_0-1684875886043.png

 

RobertOliverNZ_1-1684875629258.png

 

 

@RobertOliverNZ 

Use the following steps:

  1. Open your Word document and navigate to the Developer tab. If you don't see the Developer tab in the ribbon, you'll need to enable it first. Go to "File" > "Options" > "Customize Ribbon" and check the box next to "Developer" in the right-hand column. Then click "OK."

  2. In the Developer tab, click on the "Design Mode" button in the Controls group to enable design mode.

  3. Click on the Combo Box Content Control button in the Controls group to insert a combo box into your document.

  4. Right-click on the combo box and choose "Properties" from the context menu.

  5. In the Content Control Properties dialog box, go to the "Dropdown List Properties" tab.

  6. In the "Display Name" column, enter the full names of the persons (e.g., "John Smith" or "Mary Jones") and in the "Value" column, enter their corresponding initials (e.g., "JS" or "MJ"). You can add multiple items by clicking the "Add" button.

  7. Click "OK" to close the Content Control Properties dialog box.

  8. Click on the "Design Mode" button again to disable design mode.

Now, when users interact with the combo box, they will see the full names in the drop-down list, but once they make a selection, only the initials will populate the field.

 

Please note that these instructions are based on the version of Word you mentioned (Microsoft 365 MSO, Version 2304, Build 16.0.16327.20200). The steps may vary slightly if you are using a different version of Word.

 

@NikolinoDE

 

I have followed these steps exactly and still no luck. Please see attached video or a screen recording of me carrying out these steps. See below link for this.

 

Screen Recording 

@RobertOliverNZ 

I apologize for the confusion. Achieving the desired functionality without using VBA is not possible in Word with the version you mentioned (Microsoft 365 MSO, Version 2304, Build 16.0.16327.20200). The functionality to dynamically populate a field with the initials based on a selected item from a combo box drop-down list requires the use of VBA.

Here are all the steps how you can do it:

  1. Open your Word document and navigate to the Developer tab. If you don't see the Developer tab in the ribbon, you'll need to enable it first. Go to "File" > "Options" > "Customize Ribbon" and check the box next to "Developer" in the right-hand column. Then click "OK."
  2. In the Developer tab, click on the "Design Mode" button in the Controls group to enable design mode.
  3. Click on the Combo Box Content Control button in the Controls group to insert a combo box into your document.
  4. Right-click on the combo box and choose "Properties" from the context menu.
  5. In the Content Control Properties dialog box, go to the "Dropdown List Properties" tab.
  6. In the "Display Name" column, enter the full names of the persons (e.g., "John Smith" or "Mary Jones") and in the "Value" column, enter their corresponding initials (e.g., "JS" or "MJ"). You can add multiple items by clicking the "Add" button.
  7. Click "OK" to close the Content Control Properties dialog box.
  8. Double-click on the combo box to open the VBA editor.
  9. In the VBA editor, paste the following code: 

 

Private Sub ComboBox1_Change()
    Dim fullName As String
    Dim initials As String
    
    fullName = ComboBox1.Text
    initials = GetInitials(fullName)
    
    ActiveDocument.SelectContentControlsByTitle("ComboBox1").Item(1).Range.Text = initials
End Sub

Function GetInitials(fullName As String) As String
    Dim nameParts() As String
    Dim i As Integer
    
    nameParts = Split(fullName)
    GetInitials = ""
    
    For i = LBound(nameParts) To UBound(nameParts)
        GetInitials = GetInitials & Left(nameParts(i), 1)
    Next i
End Function​

10. Close VBA Editor.

 

Now, when users select a person's full name from the combo box, the field will be populated with the corresponding initials.

That these instructions are based on the version of Word you mentioned (Microsoft 365 MSO, Version 2304, Build 16.0.16327.20200). 

 

I hope that all misunderstandings have been cleared up and that the instructions will be successful in your plans :smile:.

Hello - I need help with the same thing, however, my display names are different locations and the value needs to be their addresses. Can you help with this?

@briannabang Assuming that you are using Content Controls as was originally the case in this thread, you will need to use the ContentControlOnExit property to get hold of the item selected from the dropdown list and then by reference to a source where you have the corresponding addresses obtain the address for insertion in the required location.  

 

If you are not fixed on using Content Controls, it can be better to make use of a UserForm.

See the following pages of Greg Maxey's website :

http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm

http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm

Populate Microsoft Word Documents with Power Automate addressing the limitations of the Word Online connector including the 'The input size is too large. Please make sure the size is less than 10MB' Error References Supporting Encodian Blog Post: ...

@NikolinoDE 

 

I am trying to achieve the same result as the op but I am having major issues making this work. I think  I found where the code should go, but I don't get there by double clicking the combo box, and also the code where I am pasting it doesn't seem to work.

Are you able to break it down a little more?