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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching multiple tables for a field

Status
Not open for further replies.

OpIv37

Technical User
Jul 7, 2003
4
US
I need to find a password field in a db of hundreds of tables. Is there any way to globally search all of the tables to find which one contains the field?

Thanks in advance-
 
Hello

The below code cycles through each field in a table called tblStaff and displays in a message box the field name.

Dim db As Database
Dim rs As DAO.Recordset
Dim fld As Field
'
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblStaff")
'
For Each fld In rs.Fields
msgbox fld.Name
Next fld
rs.Close
CurrentDb.Close



Regards
Mark

 
A starting point:
Code:
Sub Determine_If_A_Field_Exist(strFieldName As String)
Dim Dbs As Database
Dim Table_Definition As TableDef
Dim fldLoop As DAO.Field

Set Dbs = CurrentDb
For Each Table_Definition In Dbs.TableDefs
  For Each fldLoop In Table_Definition.Fields
    If fldLoop.Name = strFieldName Then
      Debug.Print strFieldName & " exists in " & Table_Definition.Name
      Exit For
    End If
  Next
Next
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top