Find fields in multiple tables

V

Vic

We would like to search through many tables in a database
for a particular field. We have about 100 tables in the
database.
Is there a fairly simple method to find a particular field
in this situation, and also the table it resides in
(without having to open and search every table)?
 
J

John Vinson

We would like to search through many tables in a database
for a particular field. We have about 100 tables in the
database.
Is there a fairly simple method to find a particular field
in this situation, and also the table it resides in
(without having to open and search every table)?

Are you searching for the field by the *name* of the field, or by its
*content*? If by name, you'll need to loop through the database's
Tabledefs collection and each table's Fields collection; or you could
use Tools... Analyze... Documentor, print to a file, and search the
file for the fieldname.

Air code for the loop:

Public Sub FindField(strFieldname As String)
Dim db As DAO.Database
Dim td As DAO.Tabledef
Dim fld As Field
Set db = CurrentDb
For Each td In db.Tabledefs
If Left(td.Name, 4) <> "MSys" Then ' omit system tables
For Each fld In td.Fields
If fld.Name = strFieldname Then
Debug.Print "Field " & strFieldname & " found in " & td.Name
End If
Next fld
Next td
End Sub

If you're searching by field content - please explain; this seems a
VERY strange thing to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top