Dav,
You example code brings back fond memories. I lived three years at 56 Victoria Rd. Dunoon Scotland from '88 to '91. Stomped around many of the towns in your list mainly looking for a single malt better than the ones in previous towns. Laugavulin is hard to beat!
You certainly don't need to 35 combo boxes as you've discovered or that discombobulated If... ElseIf ... construction. The tedious part is sorting out an defining your initial data structure. Once that is done it is a walk in the sun.
I've been tinkering and collaborating with Andreas Killer on a process for cascading comboboxes many levels deep. It is still a work in progress but I'm coming to the conclusion that a CustomXMLPart isan ideal place to store the component parts in Word. Here is some sample code for a paired down process:
This ensures the data is current and displays the form. Place it in a standard code module. The form has two comboboxes name comboArea and combSupplier
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oFrm As UserForm1
Add_UPdateXMLPart
Set oFrm = New UserForm1
oFrm.Show
Unload oFrm
Set oFrm = Nothing
lbl_Exit:
Exit Sub
End Sub
Sub Add_UPdateXMLPart()
Dim strXML As String
Dim oXMLPart As CustomXMLPart
On Error Resume Next
Set oXMLPart = ActiveDocument.CustomXMLParts.SelectByNamespace("Area Data").Item(1)
If Not oXMLPart Is Nothing Then
oXMLPart.Delete
End If
On Error GoTo 0
strXML = "<Data xmlns='Area Data'><Area>North<Supplier>A</Supplier><Supplier>B</Supplier></Area>" _
& "<Area>East<Supplier>C</Supplier><Supplier>D</Supplier></Area>" _
& "<Area>South<Supplier>E</Supplier><Supplier>F</Supplier></Area>" _
& "<Area>West<Supplier>G</Supplier><Supplier>H</Supplier></Area>" _
& "<Area>Dunoon<Supplier>The Breas</Supplier><Supplier>The Brewery</Supplier><Supplier>The Clansman</Supplier></Area></Data>"
Set oXMLPart = ActiveDocument.CustomXMLParts.Add
oXMLPart.LoadXML strXML
End Sub
All you have do is define the XML sting to match your need. The tedious part
This controls the form. Place it in the form module:
Option Explicit
Private m_oXMLPart As CustomXMLPart
Private m_oXMLNodes As CustomXMLNodes
Private Sub comboArea_Change()
Dim lngIndex As Long
With comboSupplier
.Clear
Set m_oXMLNodes = m_oXMLPart.SelectNodes("/ns0:Data/ns0:Area[" & comboArea.ListIndex + 1 & "]/*")
For lngIndex = 1 To m_oXMLNodes.Count
.AddItem m_oXMLNodes(lngIndex).Text
Next
End With
lbl_Exit:
Set m_oXMLNodes = Nothing
Exit Sub
End Sub
Private Sub UserForm_Initialize()
Dim lngIndex As Long
Set m_oXMLPart = ActiveDocument.CustomXMLParts.SelectByNamespace("Area Data").Item(1)
Set m_oXMLNodes = m_oXMLPart.SelectNodes("/ns0:Data/ns0:Area")
comboArea.MatchRequired = True
For lngIndex = 1 To m_oXMLNodes.Count
comboArea.AddItem m_oXMLNodes(lngIndex).ChildNodes(1).Text
Next
lbl_Exit:
Set m_oXMLNodes = Nothing
Exit Sub
End Sub