#1
|
|||
|
|||
Link text field to dropdown list
Hi all,
i'm looking for a way to link a text control's content to the selection from a drop-down list. Say for example I choose a room from a drop down list "Room 1", "Room 2", 'Room 3" etc, then the linked text field should automatically display the amount of seats. I assume I'll have to make a hidden table with all data, but don't now how to do this. Is this possible in Word, and if so, how is it done? Thanks in advance! Borus |
#2
|
||||
|
||||
You will need a macro in the ThisDocument module of the document, and save the document as macro enabled. Name the dropdown 'Room' and the text CC as 'Seats' then change the case statements to reflect the number of seats for each room in the list (only three shown in the example). Then when you leave the dropdown, the text field is updated according to the selection.
Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim oCC As ContentControl For Each oCC In ActiveDocument.ContentControls If oCC.Title = "Room" Then Select Case oCC.Range.Text Case "Room 1" ActiveDocument.SelectContentControlsByTitle("Seats").Item(1).Range.Text = "63 Seats" Case "Room 2" ActiveDocument.SelectContentControlsByTitle("Seats").Item(1).Range.Text = "25 Seats" Case "Room 3" ActiveDocument.SelectContentControlsByTitle("Seats").Item(1).Range.Text = "42 Seats" Case Else ActiveDocument.SelectContentControlsByTitle("Seats").Item(1).Range.Text = ActiveDocument.SelectContentControlsByTitle("Seats").Item(1).PlaceholderText End Select End If Next oCC lbl_Exit: Set oCC = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Works - Thank you!
Works like a charm!
I was hoping this could be done without Visual Basic, but I'm glad it works. Thanks a lot! |
#4
|
|||
|
|||
Modification of the code
Thanks! Works well, I have one question. Is there a way to modify the code so that the users can edit the number of seats in the text field? It automatically refreshes each time I Exit the text field, which from what I understand, is the way the code works, but I am using it for slightly different use-case and I would like to give the users the option to change the text without having to go to Visual Basic.
I cant seem to figure it out. Thanks a lot in advance! Lukas |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Conditionally Color Formatting Text selected from a dropdown list in Word 2010 | pgammag | Word | 9 | 08-20-2019 04:17 PM |
make text form field active dependent on dropdown | Glenn0004 | Word VBA | 1 | 06-23-2015 06:13 PM |
VBA: How to place dropdown list next to text | YigalB | Word VBA | 0 | 08-11-2013 01:48 PM |
Macro to populate a text form field based on dropdown selection | koloa | Word | 0 | 10-20-2011 11:52 AM |
Forms: combination of a list and a text field to be filled in | bart014 | Word | 0 | 04-23-2010 12:55 AM |