Consulting

Results 1 to 18 of 18

Thread: how to reset dependent drop boxes in MS Word?

  1. #1
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location

    how to reset dependent drop boxes in MS Word?

    Hi all,
    I have 4 dependent drop down boxes in MS Word, once I've made my selections and got the result in drop down box# 4, I want to reset all the boxes (by selecting "New Clauses" in the first box). Question is how do I do this?
    Below are the 4 modules.
    Thank you

    Module 1
    Sub Populatedd6ABC()
    Select Case ActiveDocument.FormFields("dd12AB").Result
    Case "New Clauses"
    With ActiveDocument.FormFields("dd6ABC").DropDown.ListEntries
    .Clear
    .Add "New Clauses "
    End With
    Case "A=No, B=No"
    With ActiveDocument.FormFields("dd6ABC").DropDown.ListEntries
    .Clear
    .Add "A=Yes, B=No, C=No"
    End With
    End Select
    End Sub

    Module 2:
    Sub Populatedd11ADEB()
    Select Case ActiveDocument.FormFields("dd6ABC").Result
    Case "A=Yes, B=No, C=No"
    With ActiveDocument.FormFields("dd11ADEB").DropDown.ListEntries
    .Clear
    .Add "A=YES, D=YES, E=YES, B=YES"
    .Add "A=YES, D=YES, E=YES, B=NO"
    .Add "A=YES, D=NO, E=YES"
    .Add "A=YES, D=NO, E=NO"
    End With
    End Select
    End Sub

    Module 3:
    Sub PopulateddSummaryChart()
    Select Case ActiveDocument.FormFields("dd11ADEB").Result
    Case "A=YES, D=YES, E=YES, B=YES"
    With ActiveDocument.FormFields("ddSummaryChart").DropDown.ListEntries
    .Clear
    .Add "(E=YES)Highest DSC level equal to or higher than COMSEC= YES"
    .Add "(E=YES)Highest DSC level equal to or higher than COMSEC= No"
    End With
    Case "A=YES, D=YES, E=NO, B=YES"
    With ActiveDocument.FormFields("ddSummaryChart").DropDown.ListEntries
    .Clear
    .Add "(E=NO)Highest DSC level equal to or higher than COMSEC= YES"
    .Add "(E=NO)Highest DSC level equal to or higher than COMSEC= No"
    End With
    Case "A=YES, D=YES, E=NO, B=NO"
    With ActiveDocument.FormFields("ddSummaryChart").DropDown.ListEntries
    .Clear
    .Add "(E=NO, B=NO)Highest DSC Level= Protected"
    .Add "(E=NO, B=NO)Highest DSC Level= Classified"
    End With
    Case "A=YES, D=YES, E=YES, B=NO"
    With ActiveDocument.FormFields("ddSummaryChart").DropDown.ListEntries
    .Clear
    .Add "(E=YES, B=NO)Highest DSC Level= Protected"
    .Add "(E=YES, B=NO)Highest DSC Level= Classified"
    End With
    Case "A=YES, D=NO, E=YES"
    With ActiveDocument.FormFields("ddSummaryChart").DropDown.ListEntries
    .Clear
    .Add "(E=YES)Highest DSC Level= Protected"
    .Add "(E=YES)Highest DSC Level= Classified"
    End With
    Case "A=YES, D=NO, E=NO"
    With ActiveDocument.FormFields("ddSummaryChart").DropDown.ListEntries
    .Clear
    .Add "(E=NO)Highest DSC Level= Protected"
    .Add "(E=NO)Highest DSC Level= Classified"
    End With
    End Select
    End Sub

    Module 4:
    Sub PopulateddSeeNote()
    Select Case ActiveDocument.FormFields("ddSummaryChart").Result
    Case "(E=YES)Highest DSC level equal to or higher than COMSEC= YES"
    With ActiveDocument.FormFields("ddSeeNote").DropDown.ListEntries
    .Clear
    .Add "11B=YES & 11C=Yes - see note: 1"
    .Add "11B=YES & 11C=NO - see note: 3"
    End With
    Case "(E=NO)Highest DSC level equal to or higher than COMSEC= YES"
    With ActiveDocument.FormFields("ddSeeNote").DropDown.ListEntries
    .Clear
    .Add "11B=YES & 11C=Yes - see note: 8"
    .Add "11B=YES & 11C=NO - see note: 9"
    End With
    Case "(E=YES)Highest DSC level equal to or higher than COMSEC= No"
    With ActiveDocument.FormFields("ddSeeNote").DropDown.ListEntries
    .Clear
    .Add "11B=YES - ERROR SEE NOTE: 2"
    End With
    Case "(E=NO)Highest DSC level equal to or higher than COMSEC= No"
    With ActiveDocument.FormFields("ddSeeNote").DropDown.ListEntries
    .Clear
    .Add "11E=NO & 11B=YES - ERROR SEE NOTE: 10"
    End With
    Case "(E=NO, B=YES)Highest DSC Level= Protected"""
    With ActiveDocument.FormFields("ddSeeNote").DropDown.ListEntries
    .Clear
    .Add "11B=NO & 11C=Yes - see note: 4"
    .Add "11B=NO & 11C=NO - see note: 5"
    End With
    Case "(E=NO, B=NO)Highest DSC Level= Protected"""
    With ActiveDocument.FormFields("ddSeeNote").DropDown.ListEntries
    .Clear
    .Add "11B=NO & 11C=Yes - see note: 11"
    .Add "11B=NO & 11C=NO - see note: 12"
    End With
    Case "(E=YES, B=NO)Highest DSC Level= Classified"
    With ActiveDocument.FormFields("ddSeeNote").DropDown.ListEntries
    .Clear
    .Add "11B=NO & 11C=Yes - see note: 6"
    .Add "11B=NO & 11C=NO - see note: 7"
    End With
    Case "(E=NO, B=NO)Highest DSC Level= Classified"
    With ActiveDocument.FormFields("ddSeeNote").DropDown.ListEntries
    .Clear
    .Add "11B=NO & 11C=Yes - see note: 13"
    .Add "11B=NO & 11C=NO - see note: 14"
    End With
    End Select
    End Sub

  2. #2
    It would help if you posted the document or made it available to see how it is constructed. It would also probably be beneficial to use content controls instead of legacy form fields.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    See, for example:
    Dependent Dropdown Content Controls
    https://www.msofficeforums.com/word-...html#post77762

    Cascading Dropdown Content Controls
    https://www.msofficeforums.com/word-...html#post94603

    The same principles can be adapted for use with formfields.

    Posting formatted code and using the code tags wouldn't go astray, either.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location
    Quote Originally Posted by gmayor View Post
    It would help if you posted the document or made it available to see how it is constructed. It would also probably be beneficial to use content controls instead of legacy form fields.
    Thank you, (am a newby obviously) Macropod suggested same as you and provided a link, of a perfect example of code for the simple task I want to accomplish.

    I appreciate you spending time helping others.

  5. #5
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location
    Thank you, the dropdown content controls does exactly what I need. This will make the complicated selection of which reply I have to send back to clients so much easier (12 variables).


  6. #6
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location
    Hi Paul,
    I downloaded the Depended Dropdown Content Controls, am very impressed. Could I impose on you to add a 4th box as in "Slave2", I don't know enough of programming, I did study APL when I was in college (a few decades ago). I'm able to change the name like Master to what I need, and the content of "cases". But adding a 4th level dropdown, it beyond my capacity.
    Thank you

  7. #7
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    If you compare the code changes between the 'Content Controls - Dependent Dropdown' and 'Content Controls - Multi-Dependent Dropdown' examples in posts 2 & 12 in the linked thread, you should be able to see what would be required to extend the code for however many dependencies you want.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location
    Quote Originally Posted by macropod View Post
    If you compare the code changes between the 'Content Controls - Dependent Dropdown' and 'Content Controls - Multi-Dependent Dropdown' examples in posts 2 & 12 in the linked thread, you should be able to see what would be required to extend the code for however many dependencies you want.
    Thank you! that helps a lot, and actually I might have to add a 5th and who knows a 6th dropdown box.

  9. #9
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location

    trying to do 5 levels of drop down

    Hi Paul, I did as best I could with my limited knowledge of programing, compared the 2 level with the 3 level dropdown you made. Please take a look and let me know what's wrong. I did take courses in C++ and APL but that was "decades" ago. Anyway could you take a look, I notices "blocks" of code so I repeated them only changing the words for the dropdown menus. Thank you
    (I hope the file attached correctly)
    Attached Files Attached Files

  10. #10
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    I dodn't really know what you and Paul have been up to and Paul is semi-retired from these forums so I don't know when or if he will be back. Just for starters, you code is in a standard module (it needs to be in the ThisDocument modules) and you have no CC in the document you attached titled "Slave"
    Greg

    Visit my website: http://gregmaxey.com

  11. #11
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location
    Thanks,

    Putting the code in "ThisDocument" actually helped a lot, now I actually get choices in the dependent dropdown boxes.
    As you mentioned there's something wrong with document "Slave" that's where my code "bugs", Content Control.

    Thank you
    Pierre
    Last edited by macropod; 11-21-2020 at 11:27 PM. Reason: Deleted erroneous reference

  12. #12
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Try the attached. I've generalised the code somewhat to simplify the creation of additional levels. Note that the code now requires the max level # to be specified.
    Attached Files Attached Files
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  13. #13
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location
    That is beautiful code, it's like looking inside an old pocket watch watching the wheels go to and fro and wonder how can something so small be made so precisely and be so accurate.
    You are now my favority Ausie over TwoSetViolin on youtube ;-)

  14. #14
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location

    Tips on how to modify this amazing code for amateur programmers like me

    For those that have a very limited knowledge of VBA, (like me)

    I thought I would add a few "Tips" on how to modify this code for your needs, Macropod provided this amazing code.


    Enjoy
    Attached Files Attached Files

  15. #15
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Paul knows that I don't like to rely on the user "exiting" a content control to facilitate change. It requires mapping the CCs to a custom XMLPart but you might find the attached an interesting alternative.
    Attached Files Attached Files
    Greg

    Visit my website: http://gregmaxey.com

  16. #16
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location
    Thank you Greg, am glad visitors to this forum will have a choice. I can't write code, but I can to a small degree read and understand it.
    I can't tell if your version allows to add levels of dropdown as needed, regardless I'm sure anybody that can code would be very impressed by reading your creation.
    Paul's version is the "for dummies" like me who need code that can easily be modified to my purpose. Paul's version works great for what I need which is my boss want's me to learn a complex job function, we have no training manuals or tools. We learn by senior staff teaching us. I thought this is ridiculous and with my limited knowledge of coding, but being a "power" user of MS Office, I could come up with something. The dependent dropdown in my case it the perfect options.
    Thank you all for giving of your time, I'm sure you don't fully know how much it's appreciated.
    Pierre

  17. #17
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    The fundamental difference between what Paul provided you and what is in the file I attached is in Paul's version he leverages the built-in Content Control OnExit event to detect a change in the user's selection in the primary or one of the dependent CCs. The potential problem with that process is the user MIGHT (intentionally or accidentally) fill in the four CCs, then go change the first selection and print/save close without exiting the control. Obviously that will leave an invalid result.

    In my method the four CCs are mapped to a customXMLPart and a CustomEvent monitor is used to detect a change in the selection and process the code.

    Yes you can add levels, but if you do you will need to add a node for that new level in the customXMLPart and map the new CC to that node. Note the image below shows the XML structure for the existing map in the file I attached. XML Nodes names cannot contain spaces so the underscore "_" is used in place of the space:


    CC Map.jpg

    You can download CC Tools from here: https://gregmaxey.com/word_tip_pages...rol_tools.html
    Greg

    Visit my website: http://gregmaxey.com

  18. #18
    VBAX Regular
    Joined
    Nov 2020
    Posts
    11
    Location
    thank you very much, I've booked marked the link, quite a long read/study

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •