[Last Call] Learn how to a build a cloud-first strategyRegister Now


Loop through all tables column names

Posted on 2008-11-16
Medium Priority
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

Natchiket earned 2000 total points
ID: 22973811
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

830 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