#1
|
|||
|
|||
Multiple Dependant Drop Down Fields
I am so new to VBA Codes, I am not even considered a newbie!
I am looking to create a Word Document that has 3 dependent drop down fields. Example. First Drop Down should display a choice of : Outlet 1 or Outlet 2 Second Drop Down should display a list of department numbers based on which selection was chosen in the first drop down (ie. if they choose outlet 1, only code 010, 020, 030 show) If they choose outlet 2 then S010, S020, S030 should show) Third Drop Down should display codes based on the results of the second drop down box. (Example. If you choose 020 then code 11112 should show, if you choose S020, then S41114 should show) I see examples of coding on how to make 1 dropdown dependent on another but not how to make 2 fields dependent on each other. Is this possible? Can someone explain the how to in a extremely simple, basic way? Thanks in advance! |
#2
|
||||
|
||||
Your third dropdown seems unnecessary, since there are no options to choose from. Accordingly, all you need there is a text content control.
Now, suppose you have two dropdowns, one titled 'Master' and the other titled 'Servant', plus a text content control titled 'Slave'. If you add your 'Outlet 1' & 'Outlet 2' dropdown options to the 'Master', the following macro, added to your document's 'ThisDocument' code module, will take care of the updating: Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim i As Long, StrOut As String With ContentControl If .Title = "Master" Then Select Case .Range.Text Case "Outlet 1" StrOut = "010,020,030" Case "Outlet 2" StrOut = "S010,S020,S030" Case Else StrOut = "" End Select With ActiveDocument.SelectContentControlsByTitle("Servant")(1) .Type = wdContentControlText .Range.Text = "" .Type = wdContentControlDropdownList For i = 0 To UBound(Split(StrOut, ",")) .DropdownListEntries.Add Split(StrOut, ",")(i) Next End With ActiveDocument.SelectContentControlsByTitle("Slave")(1).Range.Text = " " End If If .Title = "Servant" Then Select Case .Range.Text Case "010" StrOut = "A1234" Case "020" StrOut = "11112" Case "030" StrOut = "Z7890" Case "S010" StrOut = "A7654" Case "S020" StrOut = "S41114" Case "S030" StrOut = "S44444" Case Else StrOut = " " End Select ActiveDocument.SelectContentControlsByTitle("Slave")(1).Range.Text = StrOut End If End With End Sub FWIW, the above is just an extension of the example given in this post: https://www.msofficeforums.com/word-...html#post77762
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
In this case Paul has given you the fish. For some possible alternate methods see:
http://gregmaxey.com/word_tip_pages/...down_list.html |
#4
|
||||
|
||||
Yeah, but the OP still has to scale, gut & cook it...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I don't know Paul. That may depend on the OP's taste. While it may sound barbaric to some, the best fish I have ever eaten was cut directly off live 6 to 8 pound Ahi (yellow fin tuna) caught while fishing off Barbers Point Oahu Hawaii ;-)
|
Tags |
multi drop down |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Inserting certain text dependant on a drop down box value | JakeLRL | Word VBA | 1 | 03-31-2016 07:37 PM |
copy row into new sheet dependant on cell data | scorpain | Excel | 1 | 03-08-2016 02:37 PM |
Drag & Drop between fields is sketchy? | johnlondon | Outlook | 1 | 03-26-2014 03:31 AM |
Data dependant on checkboxes? | ryanf | Word | 2 | 11-01-2012 05:00 AM |
Merge fields & Drop down menu's | ShadeTree | Word | 0 | 03-09-2010 08:19 AM |