We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 26,210 times

Related Categories

Preventing duplicate items in a List/ComboBox

Kimmy

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

Till the Roof comes off Till the Lights go out Till my Legs give out Can't shut my mouth I will not fall, my Wisdoms all.

Comments

  • the is not working

    Posted by kalisrinidhi on 25 Aug 2002

    when i tried your code it gives an error such next with out for please guide to mak this code working

  • logic error

    Posted by jsz00 on 08 May 2002

    :o

    The code doesn't cover the case where the item being added is in one of the existing list items, but is shorter in length. In this case the item to be added is different, but the code treats it ...