Can a collection be wrapped in access?

  • Thread starter Hector Cabrera via AccessMonster.com
  • Start date
H

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? 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
 
O

onedaywhen

Hector said:
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.

--
 
H

Hector Cabrera via AccessMonster.com

Thanks !

I did exactly what you said and it worked !

Thanks again !
 

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