Article ID: 200575
Article Last Modified on 6/23/2005
Sub EnumProperties(tDefName As String)
Dim db As Database
Dim tDef As TableDef
Dim tDefSourceTableName As String
Dim tDefProperty As Property
Dim PropCount As Integer
Dim dbPath As String
Dim tDefField As Field
Dim StartTime As Date, EndTime As Date
StartTime = Now
Set db = CurrentDb
Set tDef = db.TableDefs(tDefName)
If (tDef.Attributes And dbAttachedTable) <> 0 Then
If InStr(tDef.Connect, ".mdb") > 0 Then
tDefSourceTableName = tDef.SourceTableName
dbPath = Right$(tDef.Connect, _
Len(tDef.Connect) - _
InStr(tDef.Connect, "="))
Set db = DBEngine(0).OpenDatabase(dbPath)
Set tDef = db.TableDefs(tDefSourceTableName)
End If
End If
For Each tDefProperty In tDef.Properties
Next
For Each tDefField In tDef.Fields
For Each tDefProperty In tDefField.Properties
PropCount = PropCount + 1
Next
Next
EndTime = Now
Debug.Print
Debug.Print "Table: " & tDef.Name
Debug.Print "Number of Table and Field Properties: " & _
tDef.Properties.Count + PropCount
Debug.Print "Total Time: " & _
DateDiff("s", StartTime, EndTime) & " second(s)"
db.Close
End Sub
Option Explicit
Sub CreateProperties()
Dim db As Database
Dim tDef As TableDef
Dim prop As Property
Dim i As Integer
Set db = CurrentDb
Set tDef = db.TableDefs!Employees
For i = 1 To 700
Set prop = tDef.CreateProperty("Prop" & i, dbText, i)
tDef.Properties.Append prop
Next
tDef.Properties.Refresh
MsgBox "Number of Properties: " & tDef.Properties.Count
db.Close
End Sub
CreatePropertiesNote that the message box indicates the number of properties that were added to the Employees table. This number will include any existing properties as well.
Option Explicit
Sub EnumProperties(tDefName As String)
Dim db As Database
Dim tDef As TableDef
Dim tDefProperty As Property
Dim PropCount As Integer
Dim tDefField As Field
Dim StartTime As Date, EndTime As Date
StartTime = Now
Set db = CurrentDb
Set tDef = db.TableDefs(tDefName)
For Each tDefProperty In tDef.Properties
Next
For Each tDefField In tDef.Fields
For Each tDefProperty In tDefField.Properties
PropCount = PropCount + 1
Next
Next
EndTime = Now
Debug.Print
Debug.Print "Table: " & tDef.Name
Debug.Print "Number of Table and Field Properties: " & _
tDef.Properties.Count + PropCount
Debug.Print "Total Time: " & _
DateDiff("s", StartTime, EndTime) & " second(s)"
db.Close
End Sub
EnumProperties "Employees"Note the number of seconds it takes to enumerate through all properties of the Employees table.
EnumProperties "Employees1"Note that the number of seconds it takes to enumerate the properties of the linked table is much higher.
Keywords: kbprogramming kbprb KB200575