By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Find a field in hundreds of tables

P: n/a
I have an Access front-end that has linked tables to an Oracle database;
there are hundreds of linked tables in my front-end.

Is there a way to write some code that goes through every table and
finds all the tables that have fields named "EMPLID" and puts the names
of those tables into another table?

Help is appreciated.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The code below should give you a start. I don't see that use of Oracle is
specifically relevant here.

It requires the DAO object library to be included in your application.

You might want to add some error handling and/or restrict the table names
to those not starting with MSys (which are Access internal tables).

Regards

Peter Russell
Sub FindTables()
Dim fName
Dim db As Database
Set db = CurrentDb

Dim tbl As DAO.TableDef
Dim fld As DAO.Field

fName = "EMPLID"

For Each tbl In db.TableDefs

For Each fld In tbl.Fields
If fld.Name = fName Then
InsertRec tbl.Name
Exit For
Else
End If
Next fld

Next tbl

Set db = Nothing
End Sub

Sub InsertRec(vtblname)
' set your own table name (=MyTable) and fieldname (=tablename) where
' results are stored
Dim strSQL
strSQL = "INSERT INTO MyTable (tablename) VALUES ('"
strSQL = strSQL & vtblname & "')"
CurrentDb.Execute strSQL, dbFailOnError
End Sub


Rehmann previously wrote:
I have an Access front-end that has linked tables to an Oracle database;
there are hundreds of linked tables in my front-end.

Is there a way to write some code that goes through every table and
finds all the tables that have fields named "EMPLID" and puts the names
of those tables into another table?

Help is appreciated.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.