适用于:Access 2013、Office 2013
返回一个值,该值指示 Index 对象是否仅表示 Microsoft Access 工作区) (表中的外键。 .
语法
表达式 。外国
表达 一个代表 Index 对象的变量。
备注
返回值是一个 Boolean 数据类型,如果 Index 代表一个外键,则返回 True。
外键包括外表中的一个或多个字段,这些字段可唯一地标识主表中的所有行。
当您创建实施参照完整性的关系时,Microsoft Access 数据库引擎可创建外表的 Index 对象并设置 Foreign 属性。
示例
以下示例演示 Foreign 属性如何指示 TableDef 中的哪些 Index 对象是外键索引。 这些索引是在创建 Relation 时由 Microsoft Access 数据库引擎创建的。 外键索引的默认名称是主表名称加外表名称。 若要使该过程运行,需要使用 ForeignOutput 函数。
Sub ForeignX()
Dim dbsNorthwind As Database
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
With dbsNorthwind
' Print report on foreign key indexes from two
' TableDef objects and a QueryDef object.
ForeignOutput .TableDefs!Products
ForeignOutput .TableDefs!Orders
ForeignOutput .TableDefs![Order Details]
.Close
End With
End Sub
Function ForeignOutput(tdfTemp As TableDef)
Dim idxLoop As Index
With tdfTemp
Debug.Print "Indexes in " & .Name & " TableDef"
' Enumerate the Indexes collection of the specified
' TableDef object.
For Each idxLoop In .Indexes
Debug.Print " " & idxLoop.Name
Debug.Print " Foreign = " & idxLoop.Foreign
Next idxLoop
End With
End Function