Duplicates added to listbox


Posted by Ben on September 02, 2000 1:04 PM

How do I keep duplicates from being added to the listbox?

Posted by Ivan Moala on September 03, 0100 1:47 AM

Re: I got it -- mostly

Ben
Have you given us all the code as the above function
won't work for what you want ie
If isinbox(activecell,Listbox1) = false
won't work for your posted function.
If you have changed it and are trying to ref
the listbox1 as a Listbox then you should ref
it's name = Listbox1....the Type mismatch suggests
this ie. expecting one thing (string) getting
another eg Object and not the objects name.

Ivan

Posted by Ben on September 03, 0100 6:20 PM

Re: I got it -- mostly

Ivan, the code was:

Function isinbox(mystring As String, lb As ListBox) As Boolean

and I would get the error message with the "If isinbox(activecell, ListBox1) = False Then" statement. A mistake?



Posted by Ben on September 02, 0100 7:13 PM

I got it -- mostly

I'm using this:
Function isinbox(mystring As String) As Boolean
Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
If UCase(mystring) = UCase(ListBox1.List(i)) Then
isinbox = True
Exit Function
Else: isinbox = False
End If
Next i
End Function

But when I try to use a variable for the listbox, e.g. mystring as String, lb as ListBox, my statement "If isinbox(activecell, ListBox1) = False Then" returns a Type Mismatch error. Why is that?