By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,635 Members | 917 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,635 IT Pros & Developers. It's quick & easy.

How To Pass A Collection To A FUNCTION ??? (Access 2000) Sample Code Included

P: n/a
Hi All,

I am trying to Pass A Collection To A FUNCTION ??? (Access 2000)

I have a Class called BO (for Business Objects)

Within BO I have a Function called ShowCollection

Public Sub showcollection(colCollection As Collection)
MsgBox "colCollection(2)=" & colCollection(2)
End Sub

I've tries a whole number of ways and its not working?

The calling code is :-

Dim oCollection As New Collection
oCollection.aaa = "aaa"
oCollection.aaa = "BBB"
oCollection.aaa = "CCC"

Dim oBO As New BO
oBO.showcollection(oBO)

Any IDEA ???
Many Thanks In Advance ...

Regards

Mark Dicken
England, UK
(Currently Working in Saudi Arabia)
Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
rkc

"Mark Dicken" <ma***@trainingserve.com> wrote in message
news:3b*************************@posting.google.co m...
Hi All,

I am trying to Pass A Collection To A FUNCTION ??? (Access 2000)

I have a Class called BO (for Business Objects)

Within BO I have a Function called ShowCollection

Public Sub showcollection(colCollection As Collection)
MsgBox "colCollection(2)=" & colCollection(2)
End Sub

I've tries a whole number of ways and its not working?

The calling code is :-

Dim oCollection As New Collection
oCollection.aaa = "aaa"
oCollection.aaa = "BBB"
oCollection.aaa = "CCC"

Dim oBO As New BO
oBO.showcollection(oBO)

Any IDEA ???
Many Thanks In Advance ...


If the Sub showcollection sub is a method of your BO class and
oCollection is a member of your BO class you do not need to pass
oCollection as a parameter to the sub. Delete the
colCollection As Collection argument from the sub declaration and
it should work as expected.

Nov 12 '05 #2

P: n/a
RKC,

Thanks for the reply, that DOES makes sense. (BUT)...

The calling code is from a FORM Module and is not part of the BO
(Business Object) Class, in this sort of case the Forms can be viewed
as the PL (Presentation Layer) and what I'm trying to achieve is a
little OO and abstration... Any ideas on how I can simply have the
ability to say send in a COLLECTION of say orders and get an array
back of the orders not yet fullfilled - for example ???

Many Thanks In Advance ...

Regards

Mark Dicken
Nov 12 '05 #3

P: n/a
rkc

"Mark Dicken" <ma***@trainingserve.com> wrote in message
news:3b*************************@posting.google.co m...
RKC,

Thanks for the reply, that DOES makes sense. (BUT)...

The calling code is from a FORM Module and is not part of the BO
(Business Object) Class, in this sort of case the Forms can be viewed
as the PL (Presentation Layer) and what I'm trying to achieve is a
little OO and abstration... Any ideas on how I can simply have the
ability to say send in a COLLECTION of say orders and get an array
back of the orders not yet fullfilled - for example ???

The following class and sample procedure shows how to pass a collection
to a class, set a class property to that collection and then call a method
to read back all the members of the collection. I'd need details to be
any more specific than that.

<Class1>
Private colOrders As VBA.Collection

Public Property Set Orders(c As VBA.Collection)
Set colOrders = c
End Property

Public Sub ShowCollection()
Dim i As Integer
Dim s As String

For i = 1 To colOrders.Count
s = s & colOrders(i) & vbCrLf
Next

MsgBox s
End Sub

</Class1>
<Calling procedure>

Sub useClass1()
Dim c1 As Class1
Dim c As New VBA.Collection

Set c1 = New Class1

c.Add "Muffins"
c.Add "Bagels"
c.Add "Fried Cakes"

Set c1.Orders = c
c1.ShowCollection

Set c1 = Nothing

End Sub

</Calling procedure>
Nov 12 '05 #4

P: n/a


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5

P: n/a
Thanks RKC,

That CODE SNIPPET was GREAT.

Actually it was better than what I was expecting ...

Because it is set via a Property.

Cheers Dude.

Regards

Mark Dicken
http://www.MarkDicken.com
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.