2016-07-07 54 views
1

昨天我不得不在MS Access 2010中運行一個查詢。我需要的一個字段不在我通常使用的表中(已經通過ODBC數據庫鏈接),而且我也沒有。不知道它是哪個表的一部分(機器數據源中有幾百個表)。除了手動導入所有表格並在每個表格中查找這個字段外,還有一種方法可以在不知道表格的情況下搜索字段1.無需從ODBC數據庫中導入任何表格,或者如果沒有的話2.導入一些可能的表和搜索一次這些表已被鏈接到我的活動MS Access 2010會話?在ODBC機器數據源中搜索字段 - MS Access

回答

0

你可以使用ADO模式的一個功能做到這一點。

試試這個功能的標準模塊中:

Function ListTablesContainingField(SelectFieldName) As String 

     Dim cn As New ADODB.Connection 
     Dim rs As ADODB.Recordset 
     Dim strTempList As String   

     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) 


     rs.Close 
     Set cn = Nothing 

    End Function 
+0

這是預鏈接時表只駐留在ODBC數據庫或交當它們鏈接到Access會話? – Bradford

+0

應該適用於鏈接表或本地表 –