RELATION.Table 属性 (DAO)
适用于:Access 2013、Office 2013
指示 Relation 对象的主表的名称。 该属性应当等同于 TableDef 或 QueryDef 对象的 Name 属性设置(仅适用于 Microsoft Access 工作区)。
语法
表达式 。表
表达 一个代表 Relation 对象的变量。
备注
对于新的尚未追加到集合中的 Relation 对象, Table 属性设置是可读写的;对于 Relations 集合中的现有 Relation 对象,该属性设置是只读的。
将 Table 属性与 ForeignTable 属性一起使用,可以定义 Relation 对象(该对象表示两个表或查询中的字段间的关系)。 将 Table 属性设置为主 TableDef 或 QueryDef 对象的 Name 属性设置,将 ForeignTable 属性设置为外部(引用) TableDef 或 QueryDef 对象的 Name 属性设置。 Attributes 属性决定了两个对象之间的关系类型。
例如,如果您有一个存储在 ValidParts 表中的有效部件代码列表(这些代码存储在名为 PartNo 的字段中),则可以与 OrderItem 表建立一对多关系,这样一来,如果部件代码输入到 OrderItem 表中,它就会出现在 ValidParts 表中。 如果部件代码不存在于 ValidParts 表中,并且您未将 Relation 对象的 Attributes 属性设置为 dbRelationDontEnforce,就会发生可捕获的错误。
在此例中,ValidParts 表是主表,所以 Relation 对象的 Table 属性将设置为 ValidParts, Relation 对象的 ForeignTable 属性将设置为 OrderItem。 Relation 对象的 Fields 集合中Field 对象的 Name 和 ForeignName 属性将设置为 PartNo。
示例
以下示例演示 Table、 ForeignTable 和 ForeignName 属性如何定义两个表之间的 Relation 条件。
Sub ForeignNameX()
Dim dbsNorthwind As Database
Dim relLoop As Relation
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Debug.Print "Relation"
Debug.Print " Table - Field"
Debug.Print " Primary (One) ";
Debug.Print ".Table - .Fields(0).Name"
Debug.Print " Foreign (Many) ";
Debug.Print ".ForeignTable - .Fields(0).ForeignName"
' Enumerate the Relations collection of the Northwind
' database to report on the property values of
' the Relation objects and their Field objects.
For Each relLoop In dbsNorthwind.Relations
With relLoop
Debug.Print
Debug.Print .Name & " Relation"
Debug.Print " Table - Field"
Debug.Print " Primary (One) ";
Debug.Print .Table & " - " & .Fields(0).Name
Debug.Print " Foreign (Many) ";
Debug.Print .ForeignTable & " - " & _
.Fields(0).ForeignName
End With
Next relLoop
dbsNorthwind.Close
End Sub