vendredi 17 décembre 2021

List Index value is -1 even after selecting all items in listbox

Background: I have a userform in MS Access with a MultiColumn (2 colums) listbox, One checkbox and a command button. The Multicolumn listbox provides output via a query, the check box (name- Select all) used to select all the lines in the listbox and the command button is to get the values selected in the listbox and delete them.

Problem: The Select All check box checks all the selected items in the listbox, but when i use the command button to delete the values i still get row index as -1

Code behind the checkbox

Me.List45.SetFocus
If Me.Check55.Value = True Then 
    For i = 0 To Me.List45.ListCount
    Me.List45.Selected(i) = True
    Next i
Else
    For i = 0 To Me.List45.ListCount
    Me.List45.Selected(i) = False
    Next i

End If

Code in the Command button

rowIndex = Me.List45.ListIndex
If rowIndex = -1 Then
MsgBox "Select an Item in List Box!", vbApplicationModal
Exit Sub
End If

If i select any value in the list box and try to delete it works fine - any suggestions what i am missing here.




Aucun commentaire:

Enregistrer un commentaire