Hi All,
I am very new in the VBA coding and I've noticed this (to me strange) behavior:
Assume this code for "Value Items" type of single select two column ListBox:
1)
If List98.ListIndex > -1 Then
List98.Selected(List98.ListIndex) = False
End If
2)
List98.RowSource = ""
3)
Set rst = CurrentDb.OpenRecordset( "any query" )
rst.MoveFirst
4)
Do Until rst.EOF
List98.AddItem """" & rst![field1] & """" & ";" & """" & rst![field1] & """"
rst.MoveNext
Loop
5)
rst.Close
Let's say ListIndex was 2 before calling this code (third item is selected).
After point 1) ListIndex = -1 (no selection).
The "issue" is: When the third item is added in point 4) into the listbox the ListIndex property automatically sets itself back to 2 (the original value). Until the third item is added it remains -1. Adding next items doesn't change the ListIndex anymore so the final value is 2.
What am I doing wrong?
Thanks a lot.
juing