適用先: Access 2013、Office 2013
リレーションシップ内の外部テーブルの名前を設定または返します (Microsoft Access ワークスペースのみ)。 .
構文
式 。ForeignTable
式Relation オブジェクトを表す変数。
注釈
このプロパティは、新しい Relation オブジェクトがコレクションに追加されていない場合は値の取得および設定が可能で、 Relations コレクション内の既存の Relation オブジェクトの場合は値の取得のみ可能です。
Relation オブジェクトの ForeignTable プロパティの設定値は、外部テーブルまたはクエリを表す TableDef オブジェクトまたは QueryDef オブジェクトの Name プロパティの設定値で、 Table プロパティの設定値は、主テーブルまたはクエリを表す TableDef オブジェクトまたは QueryDef オブジェクトの Name プロパティの設定値です。
たとえば、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 の各プロパティによる 2 つのテーブル間の 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