Get the name of local table and linked table in vb

2019-08-05 18:03发布

I have five tables in my application in which two are local table and three are linked table, I'm not sure about my code how to get name of table. I want a code for provide me name of both type of table name separately using for loop.

Table Name

LocalTable1
LocalTable2
LinkTable1
LinkTable2
LinkTable3

Code

Dim td As TableDef
Dim stConnect As String
For Each td In CurrentDb.TableDefs
  Debug.Print td.Name 
Next

1条回答
不美不萌又怎样
2楼-- · 2019-08-05 18:42

You can use the source table name:

Dim db As Database
Dim tdf As TableDef

Set db = CurrentDb

For Each tdf In db.TableDefs
    If Left(tdf.Name, 4) <> "MSys" Then
        Debug.Print tdf.Name & IIf(tdf.SourceTableName <> "", "  source table: " _
            & tdf.SourceTableName, "")
    End If
Next
查看更多
登录 后发表回答