we have two listboxes. we want to populate listbox2 with selected items of listbox1. there is "Add" and "delete" bottoms. We want to make sure no duplication is present. Tommy suggested these codes, but I dont know why I can still add a repeated item from listbox1 to listbox2! ( the last lines are for populating datagrid, dont become confused)
[VBA] Private Sub cmdAdd_Click()
Dim mI As Long
Dim CheckDic As Dictionary
Set CheckDic = New Dictionary
For mI = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(mI) Then
If CheckDic.Exists(ListBox1.Selected(mI)) Then
Else
CheckDic.Add ListBox1.Selected(mI), CheckDic.Count + 1
ListBox2.AddItem ListBox1.List(mI)
r.AddNew
r.Fields(0).Value = ListBox1.List(mI)
End If
End If
Next
'Set FrmMaterialStream.DataGrid1.DataSource = r
End Sub[/VBA]