Hello,
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:
After the code is executed. Item in lstColors locks up and no more changes can be done in that listbox. I think sub "lstCars_AfterU pdate" is being called if I click on any item in lstColors, always selecting the first item.
I’m not sure what is going wrong but obviously I’m missing something, Please help.
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:
Code:
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.
Comment