Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-02-2016, 07:58 AM
jsperry jsperry is offline Multiple Dependant Drop Down Fields Mac OS X Multiple Dependant Drop Down Fields Office 2007
Novice
Multiple Dependant Drop Down Fields
 
Join Date: Apr 2016
Posts: 1
jsperry is on a distinguished road
Question 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!
Reply With Quote
  #2  
Old 04-02-2016, 03:27 PM
macropod's Avatar
macropod macropod is offline Multiple Dependant Drop Down Fields Windows 7 64bit Multiple Dependant Drop Down Fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
Naturally, you'll want to edit the code to change the outputs generated by the 'Servant'.

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]
Reply With Quote
  #3  
Old 04-03-2016, 02:52 AM
gmaxey gmaxey is offline Multiple Dependant Drop Down Fields Windows 7 32bit Multiple Dependant Drop Down Fields Office 2010 (Version 14.0)
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

In this case Paul has given you the fish. For some possible alternate methods see:
http://gregmaxey.com/word_tip_pages/...down_list.html
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 04-03-2016, 03:29 AM
macropod's Avatar
macropod macropod is offline Multiple Dependant Drop Down Fields Windows 7 64bit Multiple Dependant Drop Down Fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by gmaxey View Post
In this case Paul has given you the fish.
Yeah, but the OP still has to scale, gut & cook it...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-03-2016, 03:39 AM
gmaxey gmaxey is offline Multiple Dependant Drop Down Fields Windows 7 32bit Multiple Dependant Drop Down Fields Office 2010 (Version 14.0)
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

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 ;-)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
multi drop down



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Dependant Drop Down Fields Inserting certain text dependant on a drop down box value JakeLRL Word VBA 1 03-31-2016 07:37 PM
Multiple Dependant Drop Down Fields 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

Other Forums: Access Forums

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