ForeignName Property

See Also   Applies To

Sets or returns a value that specifies the name of the CdbField object in a foreign table that corresponds to a field in a primary table for a relationship (Microsoft Jet workspaces only).

Syntax

VOIDSetForeignName(LPCTSTR pstr );

CStringGetForeignName(VOID);

Parameters

Type Argument Description
LPCTSTR pstr A pointer to a string that contains the name of the field in a foreign table.

Remarks

Only a CdbField object that belongs to the Fields collection of a CdbRelation object can support the ForeignName property.

If the CdbRelation object isn't appended to the CdbDatabase, but the CdbField is appended to the CdbRelation object, the ForeignName property is read/write. Once the CdbRelation object is appended to the database, the ForeignName property is read-only.

The Name and ForeignName property settings for a CdbField object specify the names of the corresponding fields in the primary and foreign tables of a relationship. The Table and ForeignTable property settings for a CdbRelation object determine the primary and foreign tables of a relationship.

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 CdbRelation object to dbRelationDontEnforce, a trappable error would occur.

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

The following illustration depicts the relation described above.