This code demonstrates how to add items to a List/Combo box without duplicating any items.
Just do: Call ListAddItem(List1, "My New Item", 0)
Replace List1 with a List box/Combo box name, then name of the item your adding and whether or not its case sensitive.
Sub ListAddItem(lst As Control, sItem As String, CaseSense As Integer)
'CaseSense = 0 For CaSe SeNsItIvE
'CaseSense = 1 for not case sensitive
' works with List, Combo
For a = 0 To lst.ListCount - 1
If InStr(1, lst.List(a), sItem, CaseSense) _
And Len(lst.List(a)) = Len(sItem) Then Exit Sub
Next
lst.AddItem sItem
End Sub
Comments