Loop through all tables column names

Hi experts

can someone help me with some code that runs through all my tables and test if a string name exists as a column name?
DCRAPACCESSAsked:
Who is Participating?
 
NatchiketConnect With a Mentor Commented:
Hi this should do it ..
Function FindTables(strArg As String) As String
'--------------------------------------------------------------------
'Lists tables which have the specified string in one of the field names
'Argument strArg , string being sought
'--------------------------------------------------------------------
 
Dim db As DAO.Database
Dim tbd As DAO.TableDef
Dim fld As DAO.Field
Dim strRes As String
 
Set db = CurrentDb
 
For Each tbd In db.TableDefs
    For Each fld In tbd.Fields
        If InStr(1, fld.Name, strArg) > 0 Then
            strRes = strRes & tbd.Name & " :: " & fld.Name & vbCrLf
        End If
    Next
Next
            
Set db = Nothing
FindTables = strRes
End Function

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.