I am tring to debug someone else's code and they are using checkboxes in a listbox that is populated from a database. The code loops and fills the listbox and goes back around and if the item already exists it is suppose to put a check next to the item.

For some reason it will not work. It generates Error 381 (Invalid property array index). I think the guy is trying to make the index number of the item the same as the id in the database to determine what item is what in the listbox.

Here is a piece of the code below:


Code:
Do While Not rsData.EOF
    With lstRiskFactors                  
       .AddItem rsData.Field("id_desc") 
       .ItemData(.NewIndex) = rsData.Fields("id")

    If Not IsNull(rsData.Fields("id_riskFactor")) Then
      .Selected(rsData.Fields("id_riskFactor") - 1) = True
    End If
    End With

    rsData.MoveNext

 Loop
 rsData.Close