I'm attempting to verify that the key for a VBA collection does not already exist in the collection. I am using a list of UNIX accounts as my keys, which I've already verified is unique. I then iterate over a series of sheets containing the user data. Because of how the data is laid out, I run a two pass system, one to pick the usernames and the second to correlate data not having a username in the record. When I go to add the usernames on the first pass, sometimes it will throw an error saying that the key already exists in the collection.
My most recent attempt to overcome this error is as follows: NOTE: account is a class I wrote to store all of the information, and Accounts is the collection.
Public Function ContainsKey (key as String)
Dim retVal as Boolean
Dim record as account
retVal = False
On Error GoTo Finish
record = Account.item (key)
If not record = Empty Then
retVal = True
End If
Finish:
ContainsKey = retVal
End Function
I've stepped through the code all the way through to the error and the if statement is never executed, but it's still complaning about a duplicate key. I don't undertand what's going on with the collection, why it's throwing a duplicate key error when I'm checking for duplcates before adding them into the collections.
Any and all help is much appreciated! Thank you all in advance for your help.
Thanks, Jeremy