TheInsider
Programmer
Hi,
Why does Access ignore a relationship object's attributes, primarily the cascade update and delete?
Below is a sample of code from Access' help files, if you run this in the Northwind database, it almost does what it is supposed to do! The relationship is created but the cascade update and delete options are not set!!! You can just cut and paste this code into a module in the Northwind database to see this, or look up CreateRelation in your help file and choose "example". I guarentee that the attributes will not work! I have tried over and over again.
Sub NewRelation()
Dim dbs As Database, rel As Relation, fld As Field
' Return reference to current database.
Set dbs = CurrentDb
' Create new Relation object and specify foreign table.
Set rel = dbs.CreateRelation("CategoryProducts", "Categories", "Products"
' Set attributes to enforce referential integrity.
rel.Attributes = dbRelationUpdateCascade And dbRelationDeleteCascade
' Create field in Relation object.
Set fld = rel.CreateField("CategoryID"
' Specify field name in foreign table.
fld.ForeignName = "CategoryID"
' Append Field object to Fields collection of Relation object.
rel.Fields.Append fld
' Append Relation object to Relations collection.
dbs.Relations.Append rel
dbs.Relations.Refresh
Set dbs = Nothing
End Sub [sig][/sig]
Why does Access ignore a relationship object's attributes, primarily the cascade update and delete?
Below is a sample of code from Access' help files, if you run this in the Northwind database, it almost does what it is supposed to do! The relationship is created but the cascade update and delete options are not set!!! You can just cut and paste this code into a module in the Northwind database to see this, or look up CreateRelation in your help file and choose "example". I guarentee that the attributes will not work! I have tried over and over again.
Sub NewRelation()
Dim dbs As Database, rel As Relation, fld As Field
' Return reference to current database.
Set dbs = CurrentDb
' Create new Relation object and specify foreign table.
Set rel = dbs.CreateRelation("CategoryProducts", "Categories", "Products"
' Set attributes to enforce referential integrity.
rel.Attributes = dbRelationUpdateCascade And dbRelationDeleteCascade
' Create field in Relation object.
Set fld = rel.CreateField("CategoryID"
' Specify field name in foreign table.
fld.ForeignName = "CategoryID"
' Append Field object to Fields collection of Relation object.
rel.Fields.Append fld
' Append Relation object to Relations collection.
dbs.Relations.Append rel
dbs.Relations.Refresh
Set dbs = Nothing
End Sub [sig][/sig]