PDA

View Full Version : [SOLVED:] how to reset dependent drop boxes in MS Word?



PGG1507
11-16-2020, 05:39 PM
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

gmayor
11-16-2020, 09:53 PM
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.

macropod
11-17-2020, 12:01 AM
See, for example:
Dependent Dropdown Content Controls
https://www.msofficeforums.com/word-vba/24661-help-cascading-dropdown-list.html#post77762

Cascading Dropdown Content Controls
https://www.msofficeforums.com/word-vba/29617-creating-reducing-drop-down-list.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.

PGG1507
11-17-2020, 02:51 PM
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.:yes

PGG1507
11-17-2020, 03:02 PM
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).

:hi::clap:

PGG1507
11-18-2020, 02:59 PM
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

macropod
11-18-2020, 08:58 PM
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.

PGG1507
11-19-2020, 01:11 PM
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.

PGG1507
11-21-2020, 03:27 PM
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)

gmaxey
11-21-2020, 03:33 PM
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"

PGG1507
11-21-2020, 07:35 PM
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

macropod
11-21-2020, 11:24 PM
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.

PGG1507
11-22-2020, 05:14 AM
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 ;-)

PGG1507
11-22-2020, 09:50 AM
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

gmaxey
11-22-2020, 10:54 AM
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.

PGG1507
11-22-2020, 04:05 PM
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

gmaxey
11-22-2020, 04:24 PM
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:


27484

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

PGG1507
11-22-2020, 08:19 PM
thank you very much, I've booked marked the link, quite a long read/study :yes