Deleted

2848
1
04-01-2016 01:32 AM
JanPohle
New Contributor

deleted

0 Kudos
1 Reply
TedKowal
Occasional Contributor III

Sounds like you are wanting to do cascading events where one event triggers the next and so on...

When I do this in (Note: I am mainly a VB.Net programmer, a lot of differences between VB and VBA) the template/guideline/strategy I uses is this:

'Say I have 1 combo and 2 other sequentially dependent combo's or other types of controls
Private Sub MyForm_Initialize()
ComboBox1.Clear
ComboBox1.List = funtionToPopulateComboBox1()
ComboBox2.Clear
ComboBox3.Clear
End Sub


Private Sub ComboBox1_Change() 'Combobox Change event or Updated event   
If ComboBox1.Value = "" Then Exit Sub  'In case value was deleted/not necessary with a listbox
ComboBox2.Clear
ComboBox3.Clear
Dim selectedComboVal1 As String
selectedComboVal1 = ComboBox1.Value
Select Case selectedComboVal1
   Case "Condition1"
     conditionFilter = "ConditionArg1" 
   Case "Condition2"
     conditionFilter = "ConditionArg2"
   ...
   Case else
SubToPopulateComboBox ConditionFilter,comboBox2
end select   
End Sub


Private Sub ComboBox2_Change() 'Combobox Change event or Updated event   
If ComboBox2.Value = "" Then Exit Sub
ComboBox3.Clear
Dim selectedComboVal1 As String
selectedComboVal2 = ComboBox2.Value
Select Case selectedComboVal2
  Case "Condition1"
     conditionFilter = "ConditionArg1" 
   Case "Condition2"
     conditionFilter = "ConditionArg2"
   ...
   Case else
end select 
SubToPopulateComboBox ConditionFilter, comboBox3  
End Sub


Sub SubToPopulateComboBox(filter,cbo as ComboBox)
   Select Case  cbo.Name
      Case "ComboBox2"
      functionToPopulateCBO2(filter) 'filter is based on the previous ComboBox selection
   Case "ComboBox3"
      functionToPopulateCBO3(filter) 
  End Select
End sub