Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-20-2023, 08:53 PM
Emcke001 Emcke001 is offline auto populate multiple textbox content controls with different values from one dropbox option Windows 10 auto populate multiple textbox content controls with different values from one dropbox option Office 2021
Novice
auto populate multiple textbox content controls with different values from one dropbox option
 
Join Date: Sep 2022
Posts: 2
Emcke001 is on a distinguished road
Default auto populate multiple textbox content controls with different values from one dropbox option

Thanks in advance for any help!

In the document I'm creating I am hoping to autopopulate 2 or more text content controls with differing values based on one dropdown option.

e.g: dropdown "Choose size" has 2 options: 'Large' and 'Small'.
when a size is chosen I would like a value for its height to populate in textbox 'Height' and a separate/different value for its width to populate in textbox 'Width'



Is this do-able the way I have mentioned above? I know how to populate when only one value is required. If there is an easier/better way of completing this please point me in the right direction!
Reply With Quote
  #2  
Old 02-20-2023, 10:05 PM
gmayor's Avatar
gmayor gmayor is offline auto populate multiple textbox content controls with different values from one dropbox option Windows 10 auto populate multiple textbox content controls with different values from one dropbox option Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

If you use a ListBox content control titled 'Size' then the following macro in the ThisDocument module of the document/template will populate the two text controls with the values shown, when you click out of the list box.
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oCC As ContentControl
    If ContentControl.Title = "Size" Then
        If ContentControl.ShowingPlaceholderText = False Then
            Select Case ContentControl.Range.Text
                Case "Large"
                    Set oCC = ActiveDocument.SelectContentControlsByTitle("Height").Item(1)
                    oCC.Range.Text = "123 cm"
                    Set oCC = ActiveDocument.SelectContentControlsByTitle("Width").Item(1)
                    oCC.Range.Text = "234 cm"
                Case "Small"
                    Set oCC = ActiveDocument.SelectContentControlsByTitle("Height").Item(1)
                    oCC.Range.Text = "25 cm"
                    Set oCC = ActiveDocument.SelectContentControlsByTitle("Width").Item(1)
                    oCC.Range.Text = "36 cm"
            End Select
        Else
            Set oCC = ActiveDocument.SelectContentControlsByTitle("Height").Item(1)
            oCC.Range.Text = ""
            Set oCC = ActiveDocument.SelectContentControlsByTitle("Width").Item(1)
            oCC.Range.Text = ""
        End If
    End If
    Set oCC = Nothing
End Sub
Had there been more than two values to consider, you could have added values to the list box and split the values to provide the results.
You may find Insert Content Control Add-In useful.
__________________
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 02-20-2023, 11:05 PM
Guessed's Avatar
Guessed Guessed is offline auto populate multiple textbox content controls with different values from one dropbox option Windows 10 auto populate multiple textbox content controls with different values from one dropbox option Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,160
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can do this with a series of dropdown content controls all mapped to the same xml field if you didn't want to use a macro-enabled method.

For each CC, each dropdown entry has a Display Name and a Value. If the value matches the same value chosen in a different CC then the displayed name will change accordingly.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 02-21-2023, 12:57 PM
Emcke001 Emcke001 is offline auto populate multiple textbox content controls with different values from one dropbox option Windows 10 auto populate multiple textbox content controls with different values from one dropbox option Office 2021
Novice
auto populate multiple textbox content controls with different values from one dropbox option
 
Join Date: Sep 2022
Posts: 2
Emcke001 is on a distinguished road
Default

thanks gmayor! this works great for what I want.

Is there a way to show the test on change rather than on exit?
Also how would I repeat this for another set of listbox/text? i.e. another separate listbox with multiple values to show in different text boxes on the same document?
Reply With Quote
  #5  
Old 02-21-2023, 09:24 PM
gmayor's Avatar
gmayor gmayor is offline auto populate multiple textbox content controls with different values from one dropbox option Windows 10 auto populate multiple textbox content controls with different values from one dropbox option Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

As long as the content control titles are different, simply repeat the IF condition for the second list box & text boxes.
__________________
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear all content controls (Text, dropdown) AND change option button values to FALSE in MS Word Form Janet D Word VBA 7 01-14-2023 02:36 AM
How to use content controls to populate text throughout the same document? WordUnknown Word 6 11-01-2022 11:08 AM
auto populate multiple textbox content controls with different values from one dropbox option VBA to Populate text content controls in word from excel lmoir87 Word VBA 15 05-27-2022 04:22 PM
auto populate multiple textbox content controls with different values from one dropbox option Auto populate & auto calculate values from other sections in the same word document Frantic Word VBA 2 01-24-2015 04:54 PM
auto populate multiple textbox content controls with different values from one dropbox option Retrieve Values from Content Controls for hidden john s. Word VBA 1 02-21-2014 02:14 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:10 PM.


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