Field2.ForeignName-Eigenschaft (DAO)
Gilt für: Access 2013, Office 2013
Mit dieser Eigenschaft wird ein Wert festgelegt oder zurückgegeben, der den Namen des Field2-Objekts in einer Fremdtabelle angibt, das einem Feld in einer Primärtabelle für eine Beziehung entspricht (gilt nur für Microsoft Access-Arbeitsbereiche).
Syntax
Ausdruck . ForeignName
Ausdruck Eine Variable, die ein Field2-Objekt darstellt.
Hinweise
Wenn das Relation -Objekt nicht dem Database -Objekt sondern das Field2-Objekt dem Relation-Objekt angefügt wird, ist die ForeignName-Eigenschaft nicht schreibgeschützt. Sobald das Relation-Objekt der Datenbank angefügt wurde, ist die ForeignName-Eigenschaft schreibgeschützt.
Nur ein Field2-Objekt, das zur Fields-Auflistung eines Relation-Objekts gehört, kann die ForeignName-Eigenschaft unterstützten.
Die Einstellungen der Eigenschaften Name und ForeignName für ein Field2-Objekt geben die Namen der entsprechenden Felder in den Primär- und Fremdtabellen einer Beziehung an. Die Einstellungen der Eigenschaften Table und ForeignTable für ein Relation-Objekt bestimmen die Primär- und Fremdtabellen einer Beziehung.
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 exist 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 foreign table, so the ForeignTable property of the Relation object would be set to ValidParts and the Table property of the Relation object would be set to OrderItem. The Name and ForeignName properties of the Field2 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