Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

Code to list Tables & Fields in a mdb

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Pockmire - 17 Nov 2006 19:45 GMT
What code can I use to list all of the tables in a database, or all of the
fields in a table?
Klatuu - 17 Nov 2006 20:10 GMT
Use the built in Documenter.  It will provide a printout of whatever you
select.
Tools, Analyze, Documenter

> What code can I use to list all of the tables in a database, or all of the
> fields in a table?
fdcusa - 18 Nov 2006 07:50 GMT
Option Compare Database
Option Explicit

Public Sub TablesAndFields2()

Dim db As DAO.Database
Dim tdfs As DAO.TableDefs
Dim tdf As DAO.TableDef
Dim rst As DAO.Recordset
Dim flds As DAO.Fields
Dim fld As DAO.Field

Set db = CurrentDb()
Set tdfs = db.TableDefs
For Each tdf In tdfs
   If UCase$(Left$(tdf.Name, 4)) <> "MSYS" And UCase$(Left$(tdf.Name, 4))
<> "USYS" Then
       Debug.Print "Table Name: " & tdf.Name
       Set rst = db.OpenRecordset("SELECT * FROM [" & tdf.Name & "] WHERE
False")
       Set flds = rst.Fields
       For Each fld In flds
           Debug.Print "Field Name: " & fld.Name, "Field Type: " & fld.Type
       Next fld
       rst.Close
       Set rst = Nothing
   End If
Next tdf
db.Close

End Sub
Douglas J. Steele - 18 Nov 2006 13:55 GMT
Why bother with the recordset?

Option Compare Database
Option Explicit

Public Sub TablesAndFields2()

Dim db As DAO.Database
Dim tdfs As DAO.TableDefs
Dim tdf As DAO.TableDef
Dim flds As DAO.Fields
Dim fld As DAO.Field

Set db = CurrentDb()
Set tdfs = db.TableDefs
For Each tdf In tdfs
   If UCase$(Left$(tdf.Name, 4)) <> "MSYS" And _
     UCase$(Left$(tdf.Name, 4)) <> "USYS" Then
       Debug.Print "Table Name: " & tdf.Name
       Set flds = tdf.Fields
       For Each fld In flds
           Debug.Print "Field Name: " & fld.Name, "Field Type: " & fld.Type
       Next fld
   End If
Next tdf
db.Close

End Sub

For that matter, you don't really need to instantiate some of the objects
you are. This will work just as well:

Public Sub TablesAndFields2()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set db = CurrentDb()
For Each tdf In db.TableDefs
   If UCase$(Left$(tdf.Name, 4)) <> "MSYS" And _
     UCase$(Left$(tdf.Name, 4)) <> "USYS" Then
       Debug.Print "Table Name: " & tdf.Name
       For Each fld In tdf.Fields
           Debug.Print "Field Name: " & fld.Name, "Field Type: " & fld.Type
       Next fld
   End If
Next tdf
db.Close

Another option is to replace

   If UCase$(Left$(tdf.Name, 4)) <> "MSYS" And _
     UCase$(Left$(tdf.Name, 4)) <> "USYS" Then

with

   If (tdf.Attributes And dbSystemObject) = 0 Then

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Option Compare Database
> Option Explicit
[quoted text clipped - 28 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.