I have a form with various controls but to simplify the problem let’s say I have 2 listboxes. The selection in listbox1 controls RowSource of the listbox2. For example lstCars contains car models, if I select car model X then lstColors should give me available colors for that particular model. The problem is if I select car model X in lstCars, I want the first color in lstColors to be selected by default.
Here is a sample code:
Expand|Select|Wrap|Line Numbers
- Private Sub lstCars_AfterUpdate()
- Call SetColors()
- ‘problem is in the following statements:
- If Me.lstColors.ListCount > 0 And Me.lstColors.ItemsSelected.count < 1 then
- Me.lstColors.Selected(1) = True
- End If
- End Sub
- ‘function to change rowsource of lstColors to correspond to selection in lstCars
- SetColors()
- Me.lstColors.RowSource = “Select Color From [tbl Cars] Where Model = ‘” & me.lstCars.column(0) & “’”
- End sub
I’m not sure what is going wrong but obviously I’m missing something, Please help.