Microsoft Office Forums Can a text form field be dependent on a drop-down?

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2019, 01:28 PM
scannella scannella is offline Can a text form field be dependent on a drop-down? Windows 8 Can a text form field be dependent on a drop-down? Office 2016
Novice
Can a text form field be dependent on a drop-down?
 
Join Date: Jul 2019
Posts: 2
scannella is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 07-30-2019, 03:10 PM
Guessed's Avatar
Guessed Guessed is offline Can a text form field be dependent on a drop-down? Windows 10 Can a text form field be dependent on a drop-down? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,261
Guessed has a spectacular aura aboutGuessed has a spectacular aura aboutGuessed has a spectacular aura about
Default

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
Reply With Quote
  #3  
Old 07-31-2019, 04:46 AM
scannella scannella is offline Can a text form field be dependent on a drop-down? Windows 8 Can a text form field be dependent on a drop-down? Office 2016
Novice
Can a text form field be dependent on a drop-down?
 
Join Date: Jul 2019
Posts: 2
scannella is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Yes, it is possible if macros are enabled.

It is easier if you used Content Controls instead of legacy form fields though.
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”?
Reply With Quote
  #4  
Old 07-31-2019, 06:29 AM
gmayor's Avatar
gmayor gmayor is offline Can a text form field be dependent on a drop-down? Windows 10 Can a text form field be dependent on a drop-down? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,906
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

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
Reply With Quote
  #5  
Old 07-31-2019, 03:36 PM
Guessed's Avatar
Guessed Guessed is offline Can a text form field be dependent on a drop-down? Windows 10 Can a text form field be dependent on a drop-down? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,261
Guessed has a spectacular aura aboutGuessed has a spectacular aura aboutGuessed has a spectacular aura about
Default

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
Attached Files
File Type: docx Choose an item.docx (51.1 KB, 4 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 07-31-2019 at 03:38 PM. Reason: Added Attachment
Reply With Quote
Reply

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
Can a text form field be dependent on a drop-down? 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
Can a text form field be dependent on a drop-down? Form Field - Drop down selection causing auto text chesspupil Word VBA 7 05-09-2010 05:43 AM


All times are GMT -7. The time now is 10:22 AM.


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