Freigeben über


Relation.ForeignTable-Eigenschaft (DAO)

Gilt für: Access 2013, Office 2013

Legt den Namen der Fremdtabelle in einer Beziehung fest oder gibt den Namen zurück (nur Microsoft Access-Arbeitsbereiche). .

Syntax

Ausdruck . ForeignTable

Ausdruck Eine Variable, die ein Relation-Objekt darstellt.

Hinweise

Für diese Eigenschaft besteht bei einem neuen Relation -Objekt, das noch keiner Auflistung angefügt wurde, Lese-/Schreibzugriff, und bei einem vorhandenen Relation-Objekt in der Relations -Auflistung ist sie schreibgeschützt.

Die Einstellung der ForeignTable-Eigenschaft eines Relation-Objekts ist die Einstellung der Name -Eigenschaft des TableDef - oder QueryDef -Objekts, das die Fremdtabelle oder Abfrage darstellt. Die Einstellung der Table -Eigenschaft ist die Einstellung der Name-Eigenschaft des TableDef- oder QueryDef-Objekts, das die Primärtabelle oder Abfrage darstellt.

For example, if you had a list of valid part codes (in a field named PartNo) stored in a ValidParts table, you could establish a relationship with an OrderItem table such that if a part code were entered into the OrderItem table, it would have to already be in the ValidParts table. If the part code didn't exist in the ValidParts table and you had not set the Attributes property of the Relation object to dbRelationDontEnforce, a trappable error would occur.

In this case, the ValidParts table is the primary table, so the Table property of the Relation object would be set to ValidParts and the ForeignTable property of the Relation object would be set to OrderItem. The Name and ForeignName properties of the Field object in the Relation object's Fields collection would be set to PartNo.

Beispiel

In diesem Beispiel wird gezeigt, wie die Eigenschaften Table, ForeignTable und ForeignName die Beziehungen eines Relation-Objekts zwischen zwei Tabellen definieren.

    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