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