[AccessD] Itterate a collection

DWUTKA at marlow.com DWUTKA at marlow.com
Mon Oct 25 17:17:11 CDT 2004


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



More information about the AccessD mailing list