Greetings,
I have found, today, very odd errors in code dealing with the VBA.Collection object.
A friend has proposed that perhaps VBA returns a different error when a particular entry was not found in a completely empty VBA.Collection object verses a VBA.Collection having one or more objects inside it.
I have based my use of custom collection classes on this article:
http://www.databaseadvisors.com/new...ng custom collections in microsoft access.asp
And per the author's leading, I have associated Err 5 / "Invalid Procedure Call Or Argument" with the object not being in the collection.
Today, much to my horror, I see after one object has been placed into the VBA.Collection, the error being returned an Err 9 / "Subscript Out Of Range" instead of the anticipated 5.
So, is this the expected behavior for VBA.Collection classes?
Error coming from this Exists method:
Screen capture of the VBA Editor / Debugger / Watches window with Err 5 / "Invalid Procedure Call Or Argument" and completely empty VBA.Collection:
Screen capture of the VBA Editor / Debugger / Watches window with Err 9 / "Subscript Out Of Range" and NOT completely empty VBA.Collection:
I have found, today, very odd errors in code dealing with the VBA.Collection object.
A friend has proposed that perhaps VBA returns a different error when a particular entry was not found in a completely empty VBA.Collection object verses a VBA.Collection having one or more objects inside it.
I have based my use of custom collection classes on this article:
http://www.databaseadvisors.com/new...ng custom collections in microsoft access.asp
And per the author's leading, I have associated Err 5 / "Invalid Procedure Call Or Argument" with the object not being in the collection.
Today, much to my horror, I see after one object has been placed into the VBA.Collection, the error being returned an Err 9 / "Subscript Out Of Range" instead of the anticipated 5.
So, is this the expected behavior for VBA.Collection classes?
Error coming from this Exists method:
Code:
'Returns true if the key value or index exists in the collection
Function Exists(ByVal vntIndex As Variant) As Boolean
On Error GoTo Err_Exists
Dim objTemp As clsObjXMLFASMessagesItem
Set objTemp = m_PrivateCollection.Item(vntIndex)
Exists = True
Exit_Exists:
Set objTemp = Nothing
Exit Function
Err_Exists:
If Err.Number <> 5 Then
'Further error handling here for other error types
Call errorhandler_Logger("Class: " & TypeName(Me) & ", Function: Exists()")
End If
Exists = False
Resume Exit_Exists
End Function
Screen capture of the VBA Editor / Debugger / Watches window with Err 9 / "Subscript Out Of Range" and NOT completely empty VBA.Collection:
Attachments
Last edited: