Question : Why does the Listindex property of a Combobox reset to 0 in VBA?

I am using Access VBA.  I have a unbound combobox in a sub-form that I am using to update a recordset in the subform.  I actually don't know if that has much to do with the problem, but that is the background.

Anyway, I have populated the combobox with a SQL statement that results in two items in the combobox.  If I select the second item in the combobox (Listindex=1) it reverts back to Listindex=0.  I can't figure out why.

What's odd is that the Listindex is just fine in ctrlTechnologyCombo_AfterUpdate(), but somewhere inbetween that and ctrlTechnologyCombo_Change(), it gets set back to 0, which changes the value in my combobox.

Note that there would normally be code in ctrlTechnologyCombo_AfterUpdate() to update the displayed record after the combobox is selected, but I have commented it out in trying to figure out what is going on.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Public Sub ctrlTechnologyCombo_Initialize()
Dim iCurrentProject As Integer, strSQL As String

iCurrentProject = Me.Parent.Form.ID

strSQL = "SELECT ProjectID, TechID, FieldName FROM dbo_qryBetas WHERE ProjectID=" & iCurrentProject
Me.ctrlTechnologyCombo.RowSource = strSQL
Me.ctrlTechnologyCombo.Requery

End Sub

Private Sub ctrlTechnologyCombo_AfterUpdate()
End Sub

Private Sub ctrlTechnologyCombo_Change()
End Sub

Answer : Why does the Listindex property of a Combobox reset to 0 in VBA?

Do you know what the text and value properties of the combo are when you use the where clause versus when you do not
Random Solutions  
 
programming4us programming4us