It is unfortunate that VB5 does not provide a quick way to check if an item with a certain key exists in a collection. This results in errors if an item with an existing key is added or access is attempted with a key not existing in the collection. Typically, the On Error statement is used to trap such an error. But when working with many collections, this becomes tedious and unattractive.
This function checks to see if a given key exists in a collection.
Public Function ItemExist(mCol As Collection, Key As String) As Boolean Dim V as Variant On Error Resume Next V = mCol(Key) If Err.Number = 450 Or Err.Number = 0 Then ItemExist = True Else ItemExist = False End IfEnd Function
If Err.Number is 450, that means mCol(Key) returns an object not a generic data type. If a customized collection is created, it