>
For I = 0 to Databases.Count - 1The Count property setting is never Null. If its value is 0, there are no objects in the collection. See Also Append Method, Delete Method, Refresh Method. Example This example lists the names and total number of TableDef and QueryDef objects in the current database.
Dim dbsLocal As Database, intCount As Integer Set dbsLocal = DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
For intCount = 0 To dbsLocal.TableDefs.Count - 1Example (Microsoft Access) The following example prints the names and total number fields in an Orders table.
Debug.Print dbsLocal.TableDefs(intCount).Name
Next intCount Debug.Print dbsLocal.TableDefs.Count For intCount = 0 To dbsLocal.QueryDefs.Count - 1
Debug.Print dbsLocal.QueryDefs(intCount).Name
Next intCount Debug.Print dbsLocal.QueryDefs.Count
Sub CountFields() Dim dbs As Database, tdf as TableDef Dim intI As Integer ' Return Database variable that points to current database. Set dbs = CurrentDb Set tdf = dbs.TableDefs!Orders ' Count fields in Fields collection of TableDef object. Debug.Print tdf.Fields.Count ' List names of all fields. For Each fld In tdf.Fields Debug.Print fld.Name Next fld End SubExample (Microsoft Excel) This example displays the number of recordsets in the NWINDEX.MDB database and then enters the names on Sheet1. To create the NWINDEX.MDB database, run the Microsoft Excel example for the CreateDatabase method.
Dim db As Database, i As Integer Sheets("Sheet1").Activate Set db = Workspaces(0).OpenDatabase(Application.Path & "\NWINDEX.MDB") Cells(1, 1).Value = "TableDef list for " & db.Name Cells(1, 1).EntireColumn.AutoFit For i = 0 To db.TableDefs.Count - 1 Cells(i + 2, 1).Value = db.TableDefs(i).Name Next i MsgBox "There are " & db.TableDefs.Count & " TableDefs" db.Close