Hi
I have had a look at the Collection object and I think using the 'Key' property may be a better bet for this purpose as this is the property that causes the error (it will not allow the same key for more that one 'Item' in a given collection - the Item can be any, repeated, object).
So perhaps this would be better
Code:
Sub TsetCollection()
Dim cFruit As New Collection
With cFruit
.Add "Grape", "Grape1"
.Add "Grape", "Grape2"
.Add "Apple", "Apple"
.Add "Pear", "Pear"
.Add "Peach", "Peach"
End With
MsgBox fPartExists(cFruit, "GrapeX")
MsgBox fPartExists(cFruit, "APPLE")
End Sub
Function fPartExists(ByVal oCol As Collection, ByVal ListKeyVal As String)
Dim Dummy As String
On Error Resume Next
Dummy = oCol.Item(ListKeyVal)
If Err.Number = 0 Then
fPartExists = True
Else
fPartExists = False
End If
End Function
As note the position of the items may change as the oject are added/removed, but the Key will always be the same for a given Item (I think!?).
What do you think?
MTB