Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print table and field names into Immediate window

How to

Print table and field names into Immediate window

by  randysmid  Posted    (Edited  )
Hi,
Here is a sample bit of code that will search all the tables and will print table and field names. This code should be placed in a module. As you probably know, the Debug.Print statement will put the results in the Immediate window (accessed via CTRL-G). If necessary, you can then highlight the code and paste into Word, then print.

Public Sub GetTableObjects()
Dim db As Database
Dim tbl As TableDef
Dim Fld As Field
Set db = CurrentDb
For Each tbl In db.TableDefs
Debug.Print "Table: " & tbl.Name & " ***"
For Each Fld In tbl.Fields
Debug.Print Fld.Name
Next Fld
Next tbl
End Sub

You can easily run this code from inside the Module object. Open up the module, place the cursor on the title line (Public Sub Get.....), then click the Run Macro button (arrow pointing to the right).

You may need to set some references to get to the different properties (such as tblFields). Here are the References I have on my database:
Visual Basic For Applications
Microsoft Access 9.0 Object Library (Access 2000)
Microsoft DAO 3.6 Object Library
OLE Automation
Microsoft Visual Basic for Applications Extensibility 5.3
Microsoft Office 9.0 Object Library

If you are not sure how to set these, you can enter the Microsoft Visual Basic editor (where you enter your code statements), then click on Tools. You can then click on References, then check your current list (they will have check marks in front of each one that is currently being utilized). Simply click on any missing references, and make sure they are in the order shown above.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top