View Single Post
 
Old 03-08-2024, 11:25 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

If this stuff was easy, anyone could do it. Here is something for you to contemplate:

Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim arrFordOptions() As String
Dim arrToyotaOptions() As String
Dim arrNissanOptions() As String
Dim oColOptions As New Collection
Dim lngIndex As Long
Dim bFord As Boolean, bToy As Boolean, bNis As Boolean
  
  arrFordOptions() = Split("Auto Pilot|Tires|mirrors", "|")
  arrToyotaOptions() = Split("Warp Drive|Tires|headlights", "|")
  arrNissanOptions() = Split("Rear facing seat|Tires|taillights", "|")
  'Let's assume the user selects Ford and Toyota so:
  bFord = True: bToy = True
  'Many times with VBA, errors can be your friend:
  On Error Resume Next
  If bFord Then
    For lngIndex = 0 To UBound(arrFordOptions)
      oColOptions.Add arrFordOptions(lngIndex), arrFordOptions(lngIndex)
    Next
  End If
  If bToy Then
    'One of the Toyota options "tires" duplicates a Ford option.
    For lngIndex = 0 To UBound(arrToyotaOptions)
      'When the tires option is hit the error is thrown because each item in the collection must have a unique key.
      oColOptions.Add arrToyotaOptions(lngIndex), arrToyotaOptions(lngIndex)
    Next
  End If
  If bNis Then
    For lngIndex = 0 To UBound(arrNissanOptions)
      oColOptions.Add arrNissanOptions(lngIndex), arrNissanOptions(lngIndex)
    Next
  End If
  'Populate your dependent list with the collection items
  For lngIndex = 1 To oColOptions.Count
    Debug.Print oColOptions.Item(lngIndex)
  Next lngIndex
    
lbl_Exit:
  Exit Sub
  
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote