[AccessD] Itterate a collection

Jim DeMarco Jdemarco at hudsonhealthplan.org
Fri Oct 22 07:06:11 CDT 2004


Two ways that I know of
:
Private Sub cmdRetrieveTablenames_Click()
   Dim cDO As cDatabaseObjects
   Dim oColl As Collection
   dim colItem As Variant
   
   Set cDO = New cDatabaseObjects
   Set oColl = cDO.TableNames
   For Each colItem in oColl
	debug.print colItem
   Next
   Set oColl = nothing
End Sub

or

Private Sub cmdRetrieveTablenames_Click()
   Dim cDO As cDatabaseObjects
   Dim oColl As Collection
   Dim i As Integer
   
   Set cDO = New cDatabaseObjects
   Set oColl = cDO.TableNames

   For i = 1 To oColl.Count
	debug.print oColl.Item(i)
   Next i
   Set oColl = nothing
End Sub

HTH

Jim DeMarco

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of S D
Sent: Friday, October 22, 2004 2: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


 



***********************************************************************************
"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".
***********************************************************************************




More information about the AccessD mailing list