当您知道列的名称时,查找表? [英] Find a table when you know the name of a column?
问题描述
我在Access中有一个数据库具有令人难以置信的数量的表。不幸的是,创建者使用非描述性的名称,所以基本上不可能通过查看它的名称来猜测表是什么。我需要紧急找到一个包含某些数据的表,我很确定我知道它的某些列的名称,或者至少包含在列名称中的单词。基本上,我需要的是某种类型的在整个数据库的每个表中的列名搜索,显示包含某些列名的所有表。
I have a DB in Access with an incredible amount of tables. Unfortunately, the creator used very non-descriptive names, so it's basically impossible to even guess what a table is for just by looking at its name. I need to urgently find a table that contains certain data, and I am pretty sure that I know the name of some of its columns, or at least words contained within the names of the columns. Basically, what I need is some kind of 'Search by column name in every table in the whole database', that shows all tables that contain certain column names.
推荐答案
此过程将列出表格名称和列名称,其名称包含您提供的文本。结果打印在立即窗口中(使用 Ctrl + g )。
This procedure will list the table name and column name for any columns whose names contain the text you supply. The results are printed in the Immediate window (go there with Ctrl+g)
Public Sub ListTablesWithColumnNamesContaining(ByVal pText As String)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb
For Each tdf In db.TableDefs
For Each fld In tdf.Fields
If InStr(1, fld.Name, pText, vbTextCompare) > 0 Then
Debug.Print tdf.Name & ":", fld.Name
End If
Next fld
Next tdf
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
End Sub
这篇关于当您知道列的名称时,查找表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!