HI
我想找到一个特定的字段,它存在于Access数据库的表中。是否有任何实用工具可以找到它?
答案 0 :(得分:1)
是的,你可以做VBA代码。我已经通过电子邮件发送给你了。
Public Function FindField(fieldname As String)
Dim db As Database
Dim td As TableDef
Dim fd As Field
Set db = DBEngine(0)(0)
db.TableDefs.Refresh
For Each td In db.TableDefs
For Each fd In td.fields
If fieldname = fd.Name Then
Debug.Print td.Name
End If
Next
Next
db.Close
End Function
答案 1 :(得分:0)
您可以使用ADO架构:
Function ListTablesContainingField(SelectFieldName) As String
''Tables returned will include linked tables
Dim cn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim strTempList As String
On Error GoTo Error_Trap
Set cn = CurrentProject.Connection
''Get names of all tables that have a column called <SelectFieldName>
Set rs = cn.OpenSchema(adSchemaColumns, _
Array(Empty, Empty, Empty, SelectFieldName))
''List the tables that have been selected
While Not rs.EOF
''Exclude MS system tables
If Left(rs!Table_Name, 4) <> "MSys" Then
strTempList = strTempList & "," & rs!Table_Name
End If
rs.MoveNext
Wend
ListTablesContainingField = Mid(strTempList, 2)
Exit_Here:
rs.Close
Set cn = Nothing
Exit Function
Error_Trap:
MsgBox Err.Description
Resume Exit_Here
End Function
答案 2 :(得分:0)
我在访问中进行了大量的维护和集成工作,而Allen Browne编写的vba模块完全是岩石。
在您的即时窗口中输入
?Findfield("myfieldname")
它将搜索您的数据库(表格,查询,表单,报告)以查找特定字段名称的使用位置。