Article ID: 109219
Article Last Modified on 1/8/2003
Sub Form_Load ()
Set MyDb = OpenDatabase("BIBLIO.MDB")
' Set AllTableDefs to definitions of all tables in the database:
Set AllTableDefs = MyDb.TableDefs
' Display names of all tables in database:
For j = 0 To AllTableDefs.Count - 1
List1.AddItem AllTableDefs(j).Name
Next
End Sub
Sub List1_Click ()
' Delete any existing entries in List2 box:
Do While list2.ListCount > 0
list2.RemoveItem 0
Loop
' Get the definition of the single table currently selected in List1:
Set SingleTableDef = MyDb(List1.List(List1.ListIndex))
' Display the properties of each field in the table:
For j = 0 To SingleTableDef.Fields.Count - 1
list2.AddItem "Field item number " & Val(j) & ":"
' Display the name of the field in the table selected in List1:
list2.AddItem SingleTableDef.Fields(j).Name
' or use the following since Fields are the default collection:
' List2.AddItem SingleTableDef(j).Name
list2.AddItem SingleTableDef.Fields(j).Size ' Size of field.
list2.AddItem SingleTableDef.Fields(j).Type ' Type of field.
' If field is an index, list the name of the index:
If j <= SingleTableDef.Indexes.Count - 1 Then
list2.AddItem "Index name: " & SingleTableDef.Indexes(j).Name
End If
' The Value property is only valid if part of a recordset:
' list2.AddItem SingleTableDef.Fields(i).Value
' The other 5 properties are valid for a field of TableDef object:
list2.AddItem SingleTableDef.Fields(j).OrdinalPosition
list2.AddItem SingleTableDef.Fields(j).CollatingOrder
list2.AddItem SingleTableDef.Fields(j).Attributes
list2.AddItem SingleTableDef.Fields(j).SourceField
list2.AddItem SingleTableDef.Fields(j).SourceTable
list2.AddItem " "
Next
End Sub
Global MyDb As Database Global SingleTableDef As TableDef Global AllTableDefs As TableDefs
Sub Form_Load ()
Dim ListSet As Snapshot, MyDB As database, MyTable As table
Set MyDB = OpenDatabase("BIBLIO.MDB")
Set MyTable = MyDB.OpenTable("Publishers") ' Open Table.
Set ListSet = MyTable.ListFields() ' Put field info in ListSet.
MyTable.Close ' Close Table.
Do While Not ListSet.EOF
list1.AddItem "Name: " & ListSet("Name")
list1.AddItem "type: " & ListSet("Type")
list1.AddItem "size: " & ListSet("Size")
list1.AddItem "Attributes: " & ListSet("Attributes")
list1.AddItem "SourceTable: " & ListSet("SourceTable")
list1.AddItem "SourceField: " & ListSet("SourceField")
list1.AddItem " "
ListSet.MoveNext
Loop
End Sub
The above program uses the BIBLIO.MDB database that ships with Visual
Basic version 3.0Name: PubID type: 4 size: 4 Attributes: 33 SourceTable: Publishers SourceField: PubID Name: Name type: 10 size: 50 Attributes: 32 SourceTable: Publishers SourceField: Name Name: Company Name type: 10 size: 255 Attributes: 32 SourceTable: Publishers SourceField: Company Name Name: Address type: 10 size: 50 Attributes: 32 SourceTable: Publishers SourceField: Address Name: City type: 10 size: 20 Attributes: 32 SourceTable: Publishers SourceField: City Name: State type: 10 size: 10 Attributes: 32 SourceTable: Publishers SourceField: State Name: Zip type: 10 size: 15 Attributes: 32 SourceTable: Publishers SourceField: Zip Name: Telephone type: 10 size: 15 Attributes: 32 SourceTable: Publishers SourceField: Telephone Name: Fax type: 10 size: 15 Attributes: 32 SourceTable: Publishers SourceField: Fax
Additional query words: 3.00
Keywords: KB109219