Discussion:
Can a collection be wrapped in access?
(too old to reply)
Hector Cabrera via AccessMonster.com
2005-02-08 14:27:19 UTC
Permalink
Goodmorning ! Any help with this issue? How can I set the needed procedure
attributes in access to have a wrapped collection class and not loose the
"For Each...Next" functionality? Am I asking too much of access? This is
what I have in the class:

Option Compare Database
Event addItem(strId As String)
Event removeItem(strId As String)

Public myCol As Collection

Private Sub Class_Initialize()
Set myCol = New Collection
End Sub

Private Sub Class_Terminate()
Set myCol = Nothing
End Sub

Public Function Add(Value As Form) As clsParticipant
On Error Resume Next
Dim objItem As New clsParticipant
objItem.Name = Value("name")
objItem.Phone = Value("phone")
objItem.Email = Value("email")
objItem.Company = Value("company")
myCol.Add objItem, objItem.Name
Set Add = objItem
On Error GoTo 0
End Function

Public Sub remove(strName As String)
myCol.remove strName
End Sub

Public Function count() As Long
count = myCol.count
End Function

Public Function Item(ByVal varIndex As Variant) As clsParticipant
Set Item = myCol.Item(varIndex)
End Function

Public Function NewEnum() As IUnknown
Set NewEnum = myCol.[_NewEnum]
End Function
--
Message posted via http://www.accessmonster.com
onedaywhen
2005-02-08 16:02:01 UTC
Permalink
Post by Hector Cabrera via AccessMonster.com
Goodmorning ! Any help with this issue? How can I set the needed procedure
attributes in access to have a wrapped collection class and not loose the
"For Each...Next" functionality?
Export the class module to disk, open in a text editor and add the
hidden lines e.g.

Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = myCol.[_NewEnum]
End Property

Save and re-import to the vba project. The procedure will not be hidden
in VBA but you may as well leave in Attribute in for next time <g>.

Jamie.

--
Hector Cabrera via AccessMonster.com
2005-02-09 12:54:38 UTC
Permalink
Thanks !

I did exactly what you said and it worked !

Thanks again !
--
Message posted via http://www.accessmonster.com
Loading...