Solved

Data tree structure

Posted on 1997-07-22
5
244 Views
Last Modified: 2006-11-17
I found it is difficult to remember the names of iterms in database. Can you list the full tree structure here something like:

Data1.Recordset.Fields(i).Name
-------------------------.Type
---------------.Fields.Count
-----.Database.Tabledefs(i).Name
--------------.Tabledefs.Count
0
Comment
Question by:victorlong
5 Comments
 
LVL 3

Expert Comment

by:ESI
ID: 1428637
You'll find an example doing exactly what u need in the DAO Reference, either under Fields or Tabledefs,....
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1428638
ESI is "Write" on.  VB contains an example in the help system showing you how to iterate through the tables and pull up all column properties.  If you give me an email address, I'll ship you some code that:

1) shows three linked listboxes, #1 all tables, # 2 columns and properties for  selected table, and #3, sample data for selected record.  All using DAO.  It calculates all space useage and average space per column for database as well as total columns in db.  I wrote it as a handy little tool, because you don't need an MSAccess sledge hammer to do a tack hammer's job!
0
 
LVL 3

Accepted Solution

by:
ChrisLewis earned 50 total points
ID: 1428639
Since no one gave you any code, try this.  Make sure you reference DAO 3.0 or 3.5

Private Sub Dir1_Change()
  File1.Path = Dir1.Path
End Sub

Private Sub Form_Load()
  Dir1.Path = "C:\My Documents"
End Sub

Sub command1_click()
  Dim dbDatabase As Database
  Dim tdefTable As TableDefs
  Dim iCount As Integer
  Dim iCount2 As Integer
 
  'Set dbDatabase = OpenDatabase(File1.Path & "\" & File1.filename, False, True, ";pwd=test")
  Set dbDatabase = OpenDatabase(File1.Path & "\" & File1.filename, False, True)
  MsgBox dbDatabase.Version
  Set tdefTable = dbDatabase.TableDefs
  Text1.Text = ""
  For iCount = 0 To tdefTable.Count - 1
    'Text1.Text = Text1.Text & tdefTable(iCount).Name & vbCrLf
    If tdefTable(iCount).Attributes <> dbSystemObject And tdefTable(iCount).Attributes <> dbHiddenObject Then
      Text1.Text = Text1.Text & tdefTable(iCount).Name & vbTab & tdefTable(iCount).Connect & vbCrLf
      For iCount2 = 0 To tdefTable(iCount).Fields.Count - 1
        Text1.Text = Text1.Text & vbTab & tdefTable(iCount).Fields(iCount2).Name
        Select Case tdefTable(iCount).Fields(iCount2).Type
        Case dbBigInt
          Text1.Text = Text1.Text & vbTab & "Big Integer"
        Case dbBinary
          Text1.Text = Text1.Text & vbTab & "Binary"
        Case dbBoolean
          Text1.Text = Text1.Text & vbTab & "Boolean"
        Case dbByte
          Text1.Text = Text1.Text & vbTab & "Byte"
        Case dbChar
          Text1.Text = Text1.Text & vbTab & "Char"
        Case dbCurrency
          Text1.Text = Text1.Text & vbTab & "Currency"
        Case dbDate
          Text1.Text = Text1.Text & vbTab & "Date / Time"
        Case dbDecimal
          Text1.Text = Text1.Text & vbTab & "Decimal"
        Case dbDouble
          Text1.Text = Text1.Text & vbTab & "Double"
        Case dbFloat
          Text1.Text = Text1.Text & vbTab & "Float"
        Case dbGUID
          Text1.Text = Text1.Text & vbTab & "Guid"
        Case dbInteger
          Text1.Text = Text1.Text & vbTab & "Integer"
        Case dbLong
          Text1.Text = Text1.Text & vbTab & "Long"
        Case dbLongBinary
          Text1.Text = Text1.Text & vbTab & "Long Binary (OLE Object)"
        Case dbMemo
          Text1.Text = Text1.Text & vbTab & "Memo"
        Case dbNumeric
          Text1.Text = Text1.Text & vbTab & "Numeric"
        Case dbSingle
          Text1.Text = Text1.Text & vbTab & "Single"
        Case dbText
          Text1.Text = Text1.Text & vbTab & "Text"
        Case dbTime
          Text1.Text = Text1.Text & vbTab & "Time"
        Case dbTimeStamp
          Text1.Text = Text1.Text & vbTab & "Time Stamp"
        Case dbVarBinary
          Text1.Text = Text1.Text & vbTab & "VarBinary"
      End Select
      Text1.Text = Text1.Text & vbTab & tdefTable(iCount).Fields(iCount2).Size & vbTab & tdefTable(iCount).Fields(iCount2).Attributes & vbCrLf
      Next
    End If
  Next iCount
 
  Set tdefTable = Nothing
  Set dbDatabase = Nothing
End Sub

There is a ton of information you can get from DAO.  Just play a round with it.

Hope this helps.

chris
0
 

Author Comment

by:victorlong
ID: 1428640
Hi ChrisLewis...,

I am confused...what is your code for? Does that print out what I heed?

I want a list / tree to show
WHAT MAY BE ADDED AFTER DATA1 AND THE DOT something like

Data1.Recordset.Fields(i).Name
Data1.Recordset.Fields(i).Type
Data1.Recordset.Fields.Count
Data1.Database.Tabledefs(i).Name
             
and whatever I don't know.

Regards.

Victor
0
 
LVL 3

Expert Comment

by:ChrisLewis
ID: 1428641
I see.  Look in the VB help file for properties of a Database Object and a TableDef object.

From the Help File:
---------------------------
Database Object
---------------------------
A Database object contains these collections, methods, and properties.

Collections
---------------------------
Containers
Properties
QueryDefs
Recordsets (Default for )
Relations
TableDefs (Default for )

Methods
---------------------------
Close
CreateProperty
CreateQueryDef
CreateRelation
CreateTableDef
Execute
MakeReplica
NewPassword
OpenRecordset
PopulatePartialSynchronize

Properties
---------------------------
CollatingOrder
Connect
Connection
DesignMasterID
Name
QueryTimeout
RecordsAffected
Replicable (user-defined)
ReplicaID
Updatable
V1xNullBehavior
Version
---------------------------
---------------------------

---------------------------
TableDef Object
---------------------------
A TableDef object contains these collections, methods, and properties.

Collections
---------------------------
Fields (Default)
Indexes
Properties
Methods
CreateField
CreateIndex
CreateProperty
OpenRecordset
RefreshLink

Properties
---------------------------
Attributes
ConflictTable
Connect
DateCreated
KeepLocal (user-defined)
LastUpdated
Name
RecordCount
Replicable (user-defined)
ReplicaFilter
SourceTableName
Updatable
ValidationRule
ValidationText
---------------------------
---------------------------

For the fields object, look at the help file.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now