#1
|
|||
|
|||
Can a text form field be dependent on a drop-down?
I am trying to create a template using legacy forms and would like a drop down field selection ex. "United States" or "Mexico" to auto populate other fields as "US" or "Mex.". Is this possible? |
#2
|
||||
|
||||
Yes, it is possible if macros are enabled.
It is easier if you used Content Controls instead of legacy form fields though.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
I have not written macros before, but would like to learn. How would you write one to read a user’s drop down selection of “United States”, then auto populate several fields with “US”?
|
#4
|
||||
|
||||
Assuming the list box is titled 'Country' and the others are titled "Short Name" the following macro in he thisdocument module will fill the short name fields with the selection from the country as US or MEX. You may find Insert Content Control Add-In useful
Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim oCC As ContentControl If ContentControl.ShowingPlaceholderText = False Then If ContentControl.Title = "Country" Then 'the title of the list box control Select Case Trim(ContentControl.Range.Text) Case "United States" For Each oCC In ActiveDocument.ContentControls If oCC.Title = "Short Name" Then 'the title of the fields used for the short version oCC.Range.Text = "US" End If Next oCC Case "Mexico" For Each oCC In ActiveDocument.ContentControls If oCC.Title = "Short Name" Then oCC.Range.Text = "MEX" End If Next oCC 'etc End Select End If End If Set oCC = Nothing End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
||||
|
||||
You can also do this without a macro by using linked Content Controls.
Firstly add a ComboBox Content Control and add entries with names and values corresponding to your pairs eg Name=Unites States, Value=US etc Select the Content Control and then show the XML Mapping pane, right click one of the available elements and 'Map to Selected Content Control' Then move your cursor somewhere else in the document and then on the same XML Mapping pane, right click on the same element and choose Insert Content Control > Plain Text Test it by changing the value of the ComboBox CC You can then copy and paste the plain text CC to the other locations. See the attached doc for this example in action
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia Last edited by Guessed; 07-31-2019 at 03:38 PM. Reason: Added Attachment |
Tags |
dropdown, form fill, legacy form |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Activate (show) a Drop-down form field when another drop-down form field is selected from | Jentis | Word VBA | 1 | 04-19-2018 09:42 PM |
Auto Populate Text On Dependent Drop Down Exit | GregStewartPTC | Word VBA | 2 | 02-27-2017 05:37 AM |
make text form field active dependent on dropdown | Glenn0004 | Word VBA | 1 | 06-23-2015 06:13 PM |
form control Field - Drop down auto text | mrtinfl | Word | 5 | 11-19-2014 06:57 AM |
Form Field - Drop down selection causing auto text | chesspupil | Word VBA | 7 | 05-09-2010 05:43 AM |