Loop through all tables column names

Posted on 2008-11-16
Last Modified: 2012-05-11
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?
    1 Comment
    LVL 17

    Accepted Solution

    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
    Set db = Nothing
    FindTables = strRes
    End Function

    Open in new window


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now