Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2023, 03:36 PM
sylvio sylvio is offline auto-populating dropdown list Windows 7 64bit auto-populating dropdown list Office 2010 32bit
Novice
auto-populating dropdown list
 
Join Date: Jan 2017
Posts: 20
sylvio is on a distinguished road
Default auto-populating dropdown list

Hi friends!



I would be grateful if you could help me with the VBA code. I would like to have programmed behavior of a drop-down list, let's call it "Test", the content of which changes depending on the selection from the list.
Let me explain.
Initially, the list has items "A", "B" and "C".
When "A" is selected, the drop-down list is automatically populated with options "A.I", "A.II" and "A.III".
If "A.I" is selected, the list is automatically populated with the new entries "A.I.a", "A.I.b" and "A.I.c".
If "A.I.a" is selected, the list is again automatically populated with the new entries "A.I.a.1", "A.I.a.2" and "A.I.a.3".
All possible combinations should be available, e.g. "A.III.a.3" "C.II.a.1" "B.I.c.3", etc.
Is this realistic?
Reply With Quote
  #2  
Old 04-01-2023, 05:43 AM
gmaxey gmaxey is offline auto-populating dropdown list Windows 10 auto-populating dropdown list Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

So if "A" is selected and the list items change from A, B, C to A.I, A.II and A.III, what is supposed to happen to the initially selected value "A" that is displayed?


Perhaps something like this:



Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim lngIndex As Long
  Select Case ContentControl.Title
    Case "Test"
      For lngIndex = ContentControl.DropdownListEntries.Count To 2 Step -1
         ContentControl.DropdownListEntries(lngIndex).Delete
      Next
      Select Case ContentControl.Range.Text
        Case "A"
           ContentControl.DropdownListEntries.Add "A.I", "A.I"
           ContentControl.DropdownListEntries.Add "A.II", "A.II"
           ContentControl.DropdownListEntries.Add "A.III", "A.III"
        Case "A.I"
           ContentControl.DropdownListEntries.Add "A.I.a", "A.I.a"
           ContentControl.DropdownListEntries.Add "A.I.b", "A.I.b"
           ContentControl.DropdownListEntries.Add "A.I.c", "A.I.c"
        Case "B"
           ContentControl.DropdownListEntries.Add "B.I", "B.I"
           ContentControl.DropdownListEntries.Add "B.II", "B.II"
           ContentControl.DropdownListEntries.Add "B.III", "B.III"
        Case "C"
           ContentControl.DropdownListEntries.Add "C.I", "C.I"
           ContentControl.DropdownListEntries.Add "C.II", "C.II"
           ContentControl.DropdownListEntries.Add "C.III", "C.III"
      End Select
  End Select
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 04-02-2023, 02:45 PM
sylvio sylvio is offline auto-populating dropdown list Windows 7 64bit auto-populating dropdown list Office 2010 32bit
Novice
auto-populating dropdown list
 
Join Date: Jan 2017
Posts: 20
sylvio is on a distinguished road
Default

Dear Gregory,

Thank you very much for your help. You got it right and offered a workable solution.
One question. To change the displayed value from the list and run the macro further, you have to make four clicks (1st to activate the CC drop down list, 2nd to activate the list, 3rd to activate the value in the list, 4th outside the CC to accept the new selected value). While not critical, is there any way to get rid of the 4th click? I mean, to make Word realize that after the 3rd click, the value is already selected, and continue the macro from there.
Reply With Quote
Reply

Tags
auto fill, content control events, dropdown list



Similar Threads
Thread Thread Starter Forum Replies Last Post
auto-populating dropdown list Auto-populating tables with 3 different conditions Deichgraf Excel 4 02-07-2023 08:58 AM
Auto-populating a word document csmall86 Word 1 12-20-2019 01:54 PM
auto-populating dropdown list Auto populate a text field based on Content Control Dropdown List matthias92701 Word VBA 2 05-02-2019 03:54 PM
auto-populating dropdown list UserForm Dropdown List Not Populating highrise955 Word VBA 14 04-10-2016 12:10 PM
auto-populating dropdown list Need help populating dropdown box antztaylor Word 3 11-06-2012 05:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:16 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