Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2015, 05:37 AM
borus borus is offline Link text field to dropdown list Windows 7 64bit Link text field to dropdown list Office 2013
Novice
Link text field to dropdown list
 
Join Date: Sep 2015
Posts: 2
borus is on a distinguished road
Question 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
Reply With Quote
  #2  
Old 09-14-2015, 06:00 AM
gmayor's Avatar
gmayor gmayor is offline Link text field to dropdown list Windows 7 64bit Link text field to dropdown list Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 09-14-2015, 06:17 AM
borus borus is offline Link text field to dropdown list Windows 7 64bit Link text field to dropdown list Office 2013
Novice
Link text field to dropdown list
 
Join Date: Sep 2015
Posts: 2
borus is on a distinguished road
Default 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!
Reply With Quote
  #4  
Old 08-16-2023, 05:36 AM
Lukas_ Lukas_ is offline Link text field to dropdown list Windows 10 Link text field to dropdown list Office 2021
Novice
 
Join Date: Aug 2023
Posts: 1
Lukas_ is on a distinguished road
Default 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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Link text field to dropdown list 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft