How to build a funciton to return primary key,alternate key and foreign key fields

T

tonyck

Hi every body. I need to create a function to return a string containin
:

A) primary key fields together with primary key names .
B)alternate key fields together with correspondingly alternate ke
names.
c)foreign key fields together with correspondingly foreign ke
names.

I be happy if some one show me how to build such funciton since i neve
refrenced reletionship keys via vba.Thank
 
A

Allen Browne

This info is available from the Relations collection.

Here's a sample of how to loop through this collection, returning the names
of the primary table, foreign table, and attributes of each relation, as
well as matching the field(s) in each relation:

Function ShowRel()
Dim db As DAO.Database
Dim rel As DAO.Relation
Dim fld As DAO.Field

Set db = CurrentDb()
For Each rel In db.Relations
Debug.Print rel.Name, rel.Table, rel.ForeignTable, rel.Attributes
For Each fld In rel.Fields
Debug.Print , fld.Name, fld.ForeignName
Next
Next

Set fld = Nothing
Set rel = Nothing
Set db = Nothing
End Function
 
Top