Why is collection failing?

F

FP1

I'm creating a wrapper class for a collection object, mainly so I can
test whether a given records exists. I'm baffled as to why I'm
getting "Invalid procedure or argument" in the exists function when I
try to extract the value, whether it actually exists or not. I've
tried collection.item and collection(item), same result. BTW, the
values are numbers that I convert to strings.

Option Compare Database
Option Explicit
'this class object extends the collection object to include an
'exists' boolean function

Private colStatus As VBA.Collection


Private Sub Class_Initialize()
Set colStatus = New Collection
End Sub
Public Sub add(item)
If exists(item) = False Then
colStatus.add (CStr(item))
End If
End Sub

Public Function count()
count = colStatus.count
End Function

Public Sub remove(item)
If exists(item) = True Then
colStatus.RemoveItem (CStr(item))
End If
End Sub

Function exists(item) As Boolean
On Error GoTo does_not_exist
Dim value As String
Dim strItem
strItem = CStr(item)
value = colStatus.item(strItem)
exists = True
Exit Function
does_not_exist:
exists = False
On Error Resume Next
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top