[AccessD] Itterate a collection

Doug Murphy dw-murphy at cox.net
Tue Oct 26 18:37:16 CDT 2004


Never mind, something was hosed in the db, I created a new one and it works
fine now.

Doug

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Doug Murphy
Sent: Tuesday, October 26, 2004 1:05 PM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Itterate a collection


All,

Having seem all the traffic on collections I decided to use one in a utility
I am building.  I get an error message of "Expected user defined type, not
project." on the code line that instantiates the collection: "Private
colListings As New collection".

Any idea what is causing this?

Doug

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of DWUTKA at marlow.com
Sent: Tuesday, October 26, 2004 11:22 AM
To: accessd at databaseadvisors.com
Subject: RE: [AccessD] Itterate a collection


True, you can just return the collection.  That is certainly an option, I'm
just used to writing activeX .dll's, where I am going to use them in ASP. In
that situation, I can't 'return' a collection, but I can return items in a
collection.  So it becomes a wrapper around the collection.

Drew

-----Original Message-----
From: Jim DeMarco [mailto:Jdemarco at hudsonhealthplan.org]
Sent: Tuesday, October 26, 2004 7:02 AM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] Itterate a collection


Drew,

You're making the assumption that the collection has already been populated
when you add a Count method to the class.  In the attached code it's being
filled when TableNames is called so a call to a count method could be
inaccurate (although a return of 0 or an error would tell you the collection
hadn't been filled).  

Also, why bother writing this method when the returned collection already
has a built in count that can be called from any variable assigned to the
class method?

Jim DeMarco

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of DWUTKA at marlow.com
Sent: Monday, October 25, 2004 6:17 PM
To: accessd at databaseadvisors.com
Subject: RE: [AccessD] Itterate a collection

What I prefer to do is create a count and Info property for the class:

So if I have a SomeObject class, and I have a SomeObjects Class, I would
have something like this:

Dim SomeObjs as Collection
Property get SomeObjectCount() As Long SomeObjectCount=SomeObjs.Count End
Get Property Get SomeObjectInfo(intPos) As SomeObject Set
SomeObjectInfo=SomeObjs(val(intPos))
End Property

Lets you loop through the collection then.

Drew

-----Original Message-----
From: S D [mailto:accessd667 at yahoo.com]
Sent: Friday, October 22, 2004 1:17 AM
To: accessd at databaseadvisors.com
Subject: [AccessD] Itterate a collection


Hi group,
 
I've got a class that returns a collection....how the $#$ call I iterate
that collection?
 
TIA
 
SD
 
Here's the code I use in my form:
Private Sub cmdRetrieveTablenames_Click()
   Dim cDO As cDatabaseObjects
   Dim oColl As Collection
   
   Set cDO = New cDatabaseObjects
   Set oColl = New Collection
   
   cDO.TableNames
   
End Sub
 
Here's the code in the class cDatabaseObjects:
Public Function TableNames() As Collection
   On Error GoTo errHandler
   
   Dim oCatalog As New ADOX.Catalog
   Dim oTableNames As New Collection
   Dim oTables As ADOX.Tables
   Dim oTable As ADOX.Table
   Dim oConnection As New ADODB.Connection
 
   Set oCatalog.ActiveConnection = CurrentProject.Connection
   Set oTables = oCatalog.Tables
 
   For Each oTable In oTables
      oTableNames.Add oTable.Name
   Next
   Set TableNames = oTableNames
errHandler:
   On Error Resume Next
   If oConnection.State <> 0 Then oConnection.Close
   Set oConnection = Nothing
   Set oCatalog = Nothing
   Set oTable = Nothing
   Set oTables = Nothing
End Function

 
 

		
---------------------------------
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


 



****************************************************************************
*******
"This electronic message is intended to be for the use only of the named
recipient, and may contain information from Hudson Health Plan (HHP) that is
confidential or privileged.  If you are not the intended recipient, you are
hereby notified that any disclosure, copying, distribution or use of the
contents of this message is strictly prohibited.  If you have received this
message in error or are not the named recipient, please notify us
immediately, either by contacting the sender at the electronic mail address
noted above or calling HHP at (914) 631-1611. If you are not the intended
recipient, please do not forward this email to anyone, and delete and
destroy all copies of this message.  Thank You".
****************************************************************************
*******

-- 
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
-- 
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


-- 
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list