Drop down list from another drop down list in Word?

G

gobonniego

I have a list that is way to long for a drop down list in Word. It's even
way too long for a combo box I know I could put it in. Is there a way for me
to have a drop down list that then triggers another drop down list? In case
I'm not being clear, I've divided my list into sections (major topics) that
aren't more than 15 items each. Can I have someone click on one of the more
general major topics and have that trigger a second list to come up from
which they can choose a more specific item?
 
D

Doug Robbins - Word MVP

The way in which I do that sort of thing is have the data in a table in a
word document with the major items one to a row in the first column of the
table and the associated minor items one to each paragraph in the adjacent
cell.

Then the userform initialize event is use to load the first combobox with
the entries from the first column in the table and the exit event from that
combobox is used to load the second combobox with the entries from the cell
in the second column of the table that corresponds to the cell from which
the item selected in the first combobox is located.

Here's the sort of code that you need to accomplish this for comboboxes
named cmbMajor and cmbMinor:

Option Explicit
Dim sourcedoc As Document, i As Integer, j As Integer,
Dim Major As Range, Minor As Range

Private Sub cmbMajor_Change()
'Remove any existing items in cmbCriteria
If cmbMinor.ListCount >= 1 Then
For j = cmbMinor.ListCount To 1 Step -1
cmbMinor.RemoveItem (j)
Next j
End If
' Modify the path in the following line so that it matches where you
saved formdata.doc
Application.ScreenUpdating = False
' Open the file containing the formdata details
Set sourcedoc = Documents.Open(FileName:="e:\worddocs\formdata.doc")
j = cmbSubject.ListIndex + 2
For i = 1 To sourcedoc.Tables(1).Cell(j, 2).Range.Paragraphs.Count
Set Minor = sourcedoc.Tables(1).Cell(j, 2).Range.Paragraphs(i).Range
Minor.End = Minor.End - 1
cmbMinor.AddItem Minor.Text
Next i
' Close the file containing the form data
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub

Private Sub UserForm_Initialize()
' Modify the path in the following line so that it matches where you
saved formdata.doc
Application.ScreenUpdating = False
' Open the file containing the formdata
Set sourcedoc = Documents.Open(FileName:="e:\worddocs\formdata.doc")
For i = 2 To sourcedoc.Tables(1).Rows.Count
Set Major = sourcedoc.Tables(1).Cell(i, 1).Range
Major.End = Major.End - 1
cmbMajor.AddItem Major.Text
Next i
' Close the file containing the form data
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub

p.s. I don't have access at the moment to projects in which I have used
this technique so I have just put it together on the spot and have not
actually tested it.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top