The concepts demonstrated in the previous two examples are included in the following example, which prints the properties of a TableDef object, the names of its fields, and the properties of each Field object and their values. The first procedure iterates through the Properties collection for the TableDef object and each Field object, and then calls the GetProperty function for each Property object in each collection. The GetProperty function returns a string containing the property’s name and value. If reading the property’s Value property returns an error, then the error message is included in the string:
Sub GetTableInfo(strDbName As String, strTableName As String) Dim dbs As Database Dim tdf As TableDef, fld As Field, prp As Property ' Open database. Set dbs = OpenDatabase(strDbName) Set tdf = dbs.TableDefs(strTableName) With tdf ' Print table properties. Debug.Print "Properties for table '" & strTableName & "':" For Each prp In tdf.Properties Debug.Print GetProperty(prp) Next prp Debug.Print ' Print fields and field properties. Debug.Print "Fields and field properties for table '" & _ strTableName & "':" For Each fld In .Fields Debug.Print "Field: " & fld.Name For Each prp In fld.Properties Debug.Print " " & GetProperty(prp) Next prp Debug.Print Next fld End With End Sub Function GetProperty(prp As Property) As String ' This procedure checks whether a property has a value. ' It returns either the value or an appropriate ' error string. Dim varValue As Variant ' Disable error handling. On Error Resume Next ' Attempt to retrieve the property value. varValue = prp.Value ' Check for an error. If Err Then varValue = "<Error: " & Err.Description & ">" End If ' Re-enable error handling. On Error GoTo 0 ' Return string. GetProperty = "Property: " & prp.Name & vbTab & vbTab & "Value: " & varValue End Function