Reputation: 886
In Access 2016 I have a multi-select listbox with a single column :-
Item 1
Item 1
Item 2
item 3
Item 3
In VBA, is there a way that I can remove duplicates from selected rows and display the remaining values in a message box. So, the following values would be displayed from the data above (assuming all rows are selected) :-
Item 1
Item 2
item 3
Upvotes: 0
Views: 227
Reputation: 715
Use a dictionary and check for duplicates before adding new item
Dim dict As Object: Set dict = CreateObject("Scripting.Dictionary")
For lngRow = 0 To ListBox.ListCount - 1
If .Selected(lngRow) Then
If Not dict.exists(ListBox.Column(0, lngRow)) Then
x.Add ListBox.Column(0, lngRow), ""
End If
Next
For Each x In dict.keys
Str = Str & x & vbNewLine
Next
MsgBox Str
Upvotes: 1