P
PacFreshAnthony via AccessMonster.com
New to classes and collections. Is there a way to test if a unique key is in
a collection? Right now I'm using this and it works - but I think there has
to be a better way.
Public Function BadgeExists(col As Collection, key As String) As Boolean
Dim check As Integer
Dim e As Employee
For Each e In Employees
If e.Badge = key Then
check = check + 1
End If
Next
BadgeExists = check
Debug.Print BadgeExists
End Function
Employee is a class and Employees is a collection of Employee. I Assign the
badge as the object key name in the collection.
I've tried using this code I found but it keeps returning false even if the
Key Exists
public Function KeyExists(col as Collection, key as String) as Boolean
Dim ret as Variant
On Error Resume Next
ret = col.Item(key) <- checked the debugger and ret is always empty
if err.Number<>0 Then
KeyExists = False
Else
KeyExists = True
End if
End function
Any Help would be appreciated
Thank you,
Anthony
a collection? Right now I'm using this and it works - but I think there has
to be a better way.
Public Function BadgeExists(col As Collection, key As String) As Boolean
Dim check As Integer
Dim e As Employee
For Each e In Employees
If e.Badge = key Then
check = check + 1
End If
Next
BadgeExists = check
Debug.Print BadgeExists
End Function
Employee is a class and Employees is a collection of Employee. I Assign the
badge as the object key name in the collection.
I've tried using this code I found but it keeps returning false even if the
Key Exists
public Function KeyExists(col as Collection, key as String) as Boolean
Dim ret as Variant
On Error Resume Next
ret = col.Item(key) <- checked the debugger and ret is always empty
if err.Number<>0 Then
KeyExists = False
Else
KeyExists = True
End if
End function
Any Help would be appreciated
Thank you,
Anthony