Results 1 to 2 of 2

Thread: No duplicate items in the listbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2000
    Posts
    140

    Post

    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

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width