I have a ListBox within MS Access and would like to find the best way to get the list item which was selected/deselected at the time of the on-click event.
Its a little more complicated than looping through the selected items, since the listbox is already loaded with some items selected. I am trying to find the single item which was affected at the time of the on-click event.
So, If the user clicks "Col2-How" in the example above, how would I determine that was the record clicked, Alternatively, if one deselects the first record, I would need to know. Any clues?
The only thing I can think of is to use an in-memory object to maintain alist of highlighted rows and track back to the selected items at the time of the click to determine the deltas?
you could use AfterUpdate event, for example the name of the listbox is 'aListbox', so try this :
Private Sub aListBox_AfterUpdate()
Dim rowIndex As Integer
Dim rowValue As String
Dim rowIsSelected As Integer
Dim result As String
' ListBox row index clicked
rowIndex = Me.aListBox.ListIndex
' Row value clicked
rowValue = Me.aListBox.Column(0)
' If row is selected return value is -1, if unselected return value 0
rowIsSelected = Me.aListBox.Selected(rowIndex)
If (rowIsSelected = -1) Then
result = rowValue & " selected"
Else
result = rowValue & " unselected"
End If
MsgBox (result)
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With