How can one search TableDefs for linked tables?

StockB picture StockB · Dec 17, 2013 · Viewed 12.3k times · Source

Looping through a set of TableDefs, how can one determine if each TableDef represents a linked table, as opposed to a local table?

Answer

HansUp picture HansUp · Dec 17, 2013

For a linked table, the TableDef.Connect property contains the connection information. But for a native table, the .Connect property is an empty string.

So you can tell which are which by examining Len() of .Connect

Dim tdf As DAO.TableDef
With CurrentDb
    For Each tdf In .TableDefs
        If Len(tdf.Connect) > 0 Then
            Debug.Print tdf.Name, tdf.Connect
        End If
    Next
End With

That approach is simpler for me to remember than tdf.Attributes And dbAttachedODBC Or tdf.Attributes And dbAttachedTable, or the ADOX approach. It is also much more concise than the ADOX approach.