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 / Database Design / December 2003

Tip: Looking for answers? Try searching our database.

Create Table of Field Names

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Sturdevant - 16 Dec 2003 16:01 GMT
How can I easily create a table containing the table names
and field names of all the other tables in a database?
Allen Browne - 16 Dec 2003 16:33 GMT
This routine assumes the target table named "TableInfo" has Text fields
called "TableName" and "FieldName":

Sub ShowAllTables()
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim tdf As DAO.TableDef
   Dim fld As DAO.Field
   Dim strTable As String

   Set db = CurrentDb()
   Set rs = db.OpenRecordset("TableInfo", dbOpenDynaset, dbAppendOnly)

   For Each tdf In db.TableDefs
       'Skip system and hidden tables.
       If ((tdf.Attributes And dbSystemObject) = 0) And ((tdf.Attributes
And dbHiddenObject) = 0) Then
           'Skip attached and temporary tables
           strTable = tdf.Name
           If (Len(tdf.Connect) = 0) And Not (strTable Like "~*") Then
               For Each fld In tdf.Fields
                   rs.AddNew
                       rs!TableName = strTable
                       rs!FieldName = fld.Name
                   rs.Update
               Next
           End If
       End If
   Next

   rs.Close
   Set rs = Nothing
   Set db = Nothing

   Debug.Print "Info written to table 'TableInfo'."
End Sub

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> How can I easily create a table containing the table names
> and field names of all the other tables in a database?
 
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.