P
Peter Hibbs
Hi All,
How can I delete a relationship between two tables using VBA code. I am
using the code below to CREATE a relationship (from the Access Developers
Handbook)
'================
Dim rel As DAO.Relation
Dim fld As DAO.Field
Dim vRelType As Long
On Error GoTo CreateRelationship_Err
Set rel = db.CreateRelation("Relation1", vPKTableName, vFKTableName,
vRelType)
Set fld = rel.CreateField(vPKFieldName)
fld.ForeignName = vFKFieldName
rel.Fields.Append fld
db.Relations.Append rel
CreateRelationship = True
.... etc
'================
where string variables
vPKTableName = the primary key table
vPKFieldName = the Primary key field in table
vFKTableName = the Foreign key table
vFKFieldName = the Foreign key field in table and
vRelType = relationship Type (=Long Int)
How can I delete a relationship using VBA code and what is the string
"Relation1" in the code above. It is presumably the 'name' of the
relationship object but where is it stored. I cannot find it in any of the
table or field properties for the relevant tables. If I need to delete a
relationship would I need to know the 'name' of the relationship given that I
know the name of the tables and fields used in the relationship.
How can I delete a relationship between two tables using VBA code. I am
using the code below to CREATE a relationship (from the Access Developers
Handbook)
'================
Dim rel As DAO.Relation
Dim fld As DAO.Field
Dim vRelType As Long
On Error GoTo CreateRelationship_Err
Set rel = db.CreateRelation("Relation1", vPKTableName, vFKTableName,
vRelType)
Set fld = rel.CreateField(vPKFieldName)
fld.ForeignName = vFKFieldName
rel.Fields.Append fld
db.Relations.Append rel
CreateRelationship = True
.... etc
'================
where string variables
vPKTableName = the primary key table
vPKFieldName = the Primary key field in table
vFKTableName = the Foreign key table
vFKFieldName = the Foreign key field in table and
vRelType = relationship Type (=Long Int)
How can I delete a relationship using VBA code and what is the string
"Relation1" in the code above. It is presumably the 'name' of the
relationship object but where is it stored. I cannot find it in any of the
table or field properties for the relevant tables. If I need to delete a
relationship would I need to know the 'name' of the relationship given that I
know the name of the tables and fields used in the relationship.