PDA

Click to See Complete Forum and Search --> : No duplicate items in the listbox


Lieu
Feb 17th, 2000, 10:43 PM
Hello everyone,

I have a list box and a combo box,the list box populates the items from what I pick in the combo box. If I pick a item from the combo box that already exists in the list box, I would like to have some kind of error message. In other words, the list box can not contain two items that are the same.

Thanks

RogerH
Feb 18th, 2000, 12:39 AM
Sub AddToList(NewItem As String, AddToList As ListBox)

Dim l As Long

For l = 0 To AddToList.ListCount - 1
If NewItem = AddToList.List(l) Then
MsgBox "Already in list"
Exit Sub
End If
Next

AddToList.AddItem NewItem

End Sub


Roger