Private Sub cmdOpen_Click()
Dim db As DAO.Database
Dim table_def As TableDef
Dim table_node As Node
Dim field_node As Node
Dim index_node As Node
Dim field_obj As Field
Dim index_obj As Index
Dim txt As String
' Open the database.
Set db = _
DAO.DBEngine(0).OpenDatabase(txtDatabaseName.Text)
' Clear the tree.
If trvDatabase.Nodes.Count > 0 Then
trvDatabase.Nodes(0).Expanded = False
trvDatabase.Nodes.Clear
End If
' Get Table information.
For Each table_def In db.TableDefs
' Display the table's information.
Set table_node = trvDatabase.Nodes.Add( _
Text:=table_def.Name)
' Display field information.
Set field_node = trvDatabase.Nodes.Add( _
Relative:=table_node, _
Relationship:=tvwChild, _
Text:="Fields")
For Each field_obj In table_def.Fields
trvDatabase.Nodes.Add _
Relative:=field_node, _
Relationship:=tvwChild, _
Text:=field_obj.Name & _
" (" & DbTypeName(field_obj.Type) & ")"
Next field_obj
' Display index information.
Set index_node = trvDatabase.Nodes.Add( _
Relative:=table_node, _
Relationship:=tvwChild, _
Text:="Indexes")
' We will not have permission to read index
' information on the system tables.
On Error Resume Next
For Each index_obj In table_def.Indexes
txt = ""
For Each field_obj In index_obj.Fields
txt = txt & ", " & field_obj.Name
Next field_obj
If Len(txt) > 0 Then txt = Mid$(txt, 3)
trvDatabase.Nodes.Add _
Relative:=index_node, _
Relationship:=tvwChild, _
Text:=index_obj.Name & _
" (" & txt & ")"
Next index_obj
On Error GoTo 0
Next table_def
db.Close
End Sub
|