Yes, here is an example:
Sub CreateRelationD AO()
Dim db As DAO.Database
Dim rel As DAO.Relation
Dim fld As DAO.Field
'Initialize
Set db = CurrentDb()
'Create a new relation.
Set rel = db.CreateRelati on("MyMainTable MyRelatedTable" )
'Define its properties.
With rel
'Specify the primary table.
.Table = "MyMainTabl e"
'Specify the related table.
.ForeignTable = "MyRelatedTable "
'Specify attributes for cascading updates and deletes.
.Attributes = dbRelationUpdat eCascade + dbRelationDelet eCascade
'Add the fields to the relation.
'Field name in primary table.
Set fld = .CreateField("M yMainTableID")
'Field name in related table.
fld.ForeignName = "MyForeignKeyID "
'Append the field.
.Fields.Append fld
'Repeat for other fields if a multi-field relation.
End With
'Save the newly defined relation to the Relations collection.
db.Relations.Ap pend rel
'Clean up
Set fld = Nothing
Set rel = Nothing
Set db = Nothing
Debug.Print "Relation created."
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"GGerard" <gg*****@nbnet. nb.ca> wrote in message
news:UG******** **************@ ursa-nb00s0.nbnet.nb .ca...
Hello
Does anyone know if it is possible with Access 2000 to
create relationships between tables using code?
Thanks
G.Gerard