MrKowz
Well-known Member
- Joined
- Jun 30, 2008
- Messages
- 6,653
- Office Version
- 365
- 2016
- Platform
- Windows
Wracking my brain on this one.
I have a class module which is populating various attributes of a list and is storing them in a collection. The collection is being built just fine, but I'm unable to figure out why the heck the collection key isn't working, despite me explicitly defining it. Have even tried defining "oldColl.Add NewProduct, key:=NewProduct.PDCN", but to no avail.
Example:
This snippet of code builds the NewProduct class object. The Contains() function returns FALSE here, despite me explicitly defining the key in the line before it. I'm expecting it to return TRUE.
Contains() Function:
I'd appreciate any help here. Thanks!
I have a class module which is populating various attributes of a list and is storing them in a collection. The collection is being built just fine, but I'm unable to figure out why the heck the collection key isn't working, despite me explicitly defining it. Have even tried defining "oldColl.Add NewProduct, key:=NewProduct.PDCN", but to no avail.
Example:
This snippet of code builds the NewProduct class object. The Contains() function returns FALSE here, despite me explicitly defining the key in the line before it. I'm expecting it to return TRUE.
Code:
Set NewProduct = New cNewProducts
NewProduct.Product = tmpProdName
NewProduct.Package = .Range("B" & i).value
NewProduct.PDCN = .Range("C" & i).value
oldColl.Add NewProduct, NewProduct.PDCN
MsgBox Contains(oldColl, NewProduct.PDCN)
Contains() Function:
Code:
Public Function Contains(col As Collection, key As Variant) As Boolean
Dim obj As Variant
On Error GoTo err
obj = col(key)
Contains = True
On Error GoTo 0
Exit Function
err:
Contains = False
End Function
I'd appreciate any help here. Thanks!