PDA

View Full Version : cascading drop down boxes



Fumer Tue
01-28-2011, 01:17 PM
In Word 2007 I am using the following code to allow a selection made in dropdown box 1 ("dropdown1")to populate a second dropdown box ("Result").

What I'd like to do is have the one selection populate six dropdown boxes - with the same stuff each time - there will be more content once I've got it working by the way.


I'm a total novice, but keen to learn!

CODE:

Option Explicit

Sub FirstFieldExit()

Dim Understanding(4) As String
Dim Using(3) As String
Dim Level2(3) As String
Dim i As Integer
Dim var

Understanding(0) = "1.2 Health & safety (worksheet)"
Understanding(1) = "2.1 Monitors (worksheet)"
Understanding(2) = "2.3 Project folders (worksheet)"
Understanding(3) = "Recap Ex (exercise)"
Understanding(4) = "3.1a Project Window 1 (worksheet)"

Using(0) = "Us1"
Using(1) = "Us2"
Using(2) = "Us3"
Using(3) = "Us4"

Level2(0) = "21"
Level2(1) = "22"
Level2(2) = "23"
Level2(3) = "24"

' use the value of the dropdown to case select condition
Select Case ActiveDocument.FormFields("Dropdown1").DropDown.Value
Case 1
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 4
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Understanding(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 2
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 4
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Using(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1
Case 3
ActiveDocument.FormFields("Result").DropDown.ListEntries.Clear
For var = 1 To 4
ActiveDocument.FormFields("Result").DropDown.ListEntries.Add Name:=Level2(i)
i = i + 1
Next
ActiveDocument.FormFields("Result").DropDown.Value = 1

End Select
End Sub

gmaxey
01-28-2011, 01:42 PM
Does the stuff here help at all:
http://gregmaxey.mvps.org/Linked_DropDown_Fields.htm

Fumer Tue
01-28-2011, 02:05 PM
Hi Greg,
I've read this article before, and it was what gave me the idea in the first place!

But the answer is no - your article tells you how to populate one drop down box, not six. And I seem to be using a different method from the one you suggest.

I want the user to make a selection in drop down box 1, which will then populate six separate drop down boxes with the same choices.

Thanks for your suggestion though, and for your great work on your site.

Fumer Tue
01-28-2011, 03:06 PM
Hey Greg,

I tried it again with your code and experimented a bit, and got what I wanted!

Thanks for the steer.

gmaxey
01-28-2011, 03:14 PM
Great.

Fumer Tue
01-28-2011, 05:08 PM
Hi again - I've got it working except for one little problem - I need an empty entry in the list for each drop down. That way if the user makes a mistake, they can remove the entry from the form. I've included this in the code - simply by inserting a "space" at the top of the list, like this:

Case "1"
With oDD.ListEntries
.Add " "

This works, sometimes. But not all the time, or in all the 5 drop down boxes I'm using. It seems a bit random in fact, but the code for each box is exactly the same.

Any ideas?