Hello Sims,
So, you can use the "DataSourceName" and "Connect" properties of the "TableDef" or "QueryDef" object to determine if it is a "Linked" table. Here is an example of some code for working with the TableDef object:
Code:
Public Sub CheckForLinkedTables()
On Error GoTo HandleErrors
Dim db As DAO.Database
Dim td As TableDef
Dim tds As TableDefs
Set db = CurrentDb
Set tds = db.TableDefs
' Loop through each of the tables to check for links
For Each td In tds
' Check the "SourceTableName" property to check if the table is linked
If Nz(td.SourceTableName, "") <> "" Then
' Get the connection string for the table in strTemp
Dim strTemp As String
strTemp = Nz(td.Connect, "")
' This is a linked table - do work here
Else
' This is NOT a linked table
End If
Next
ExitSub:
On Error Resume Next
Set td = Nothing
Set tds = Nothing
Set db = Nothing
Exit Sub
HandleErrors:
MsgBox "An error was captured!" & vbNewLine & vbNewLine & "Message: " & _
vbNewLine & Err.Description & vbNewLine & vbNewLine & "Number:" & _
Err.Number, vbExclamation, "Error"
Resume ExitSub
End Sub
So, the above code checks all of the tables in the current database to determine if they are "linked" tables or not (which is what the IF block is for in this code). The "SourceTableName" property of the "TableDef" object will have a value if the table is linked externally, otherwise it will be empty if it is a local table. And the "Connect" property stores the actual connection string to the location of the linked table. Does that all makes sense?
Anyway, I hope this is helpful, but if there is anything else I can do to help out, please just let me know!
Best Regards,