Looping thru fields in tables in tables collection

grnzbra

Registered User.
Local time
Today, 23:59
Joined
Dec 5, 2001
Messages
376
I have the following code (from Access Help) that prints out the names of my tables.

Sub AllTables()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for objects in AllTables collection.
For Each obj In dbs.AllTables
' Print name of obj.
Debug.Print obj.Name
Next obj
End Sub

I'd like to add another loop that would loop through the fields in each "obj" and print the fields associated with it. I've tried adding in the code from help for looping through the employees table in Northwind, but can't get it to work.

Any ideas for a "cheap & dirty" solution?
 
Loop through the Fields collection of each table.
 
Yes. Exactly. How?
What comes after Debug.Print obj.NAME?
If if dim fld as field, and try
for each fld in obj
it chokes.
 
Allen Browne has a very good example looping through the fields collection. This function will list the fields and field properties for a given table. I'm working on a total DB object enumeration and spinning wheels on the forms properties at the moment... I'm posting the link rather than the code. Allen has other very good examples on his site. Rather than just copy the function and use it, try to understand what it is doing. I'm doing the same... Hang in there...

' Function: TableInfo() function
' Purpose : Display the field names, types, sizes and descriptions for a table.
' Argument: Name of a table in the current database (as a string).
' Author : Allen Browne, allen@allenbrowne.com.
' Source : http://allenbrowne.com/func-06.html
' Date : Updated June 2006.
 
g,

Code:
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
For Each tdf In CurrentDb.TableDefs
   For Each fld In tdf.Fields
      Debug.Print tdf.Name & ", " & fld.Name
      Next fld
   Next tdf

Wayne
 
Wayne,
Thanks a lot. That solved my immediate problem very nicely.

fdcusa
Thank you also for pointing me to that link. It is very informative and in the near future I will be expanding the current code to include Allen's ideas.
 

Users who are viewing this thread

Back
Top Bottom