Hi,
I am wondering if there is a way to set "Cascade Update Related Fields" and "Cascade Delete Related Records" using code rather than editing the relationship and manually checking the boxes. In the data model I'm creating, all of the tables, primary and foreign keys, unique constraints, validation rules etc. are defined using a combination of inline SQL (for DDL) and VBA. The only thing that's missing is how to set the properties of the foreign key. Access gives a run-time error of '3289': "Syntax error in CONSTRAINT clause" on this inline statement:
ALTER TABLE InvoicesHeader ADD CONSTRAINT FK_InvoicesDetail_InvoicesHeader
FOREIGN KEY (InvoiceHeaderID)
REFERENCES InvoicesHeader (InvoiceHeaderID)
ON DELETE CASCADE
ON UPDATE CASCADE
However, when the last two lines are removed (ON DELETE CASCADE DELETE and ON UPDATE CASCADE) it runs fine. Does anyone know how to set the referential integrity properties in a module?
Thanks in advance, knot22
I am wondering if there is a way to set "Cascade Update Related Fields" and "Cascade Delete Related Records" using code rather than editing the relationship and manually checking the boxes. In the data model I'm creating, all of the tables, primary and foreign keys, unique constraints, validation rules etc. are defined using a combination of inline SQL (for DDL) and VBA. The only thing that's missing is how to set the properties of the foreign key. Access gives a run-time error of '3289': "Syntax error in CONSTRAINT clause" on this inline statement:
ALTER TABLE InvoicesHeader ADD CONSTRAINT FK_InvoicesDetail_InvoicesHeader
FOREIGN KEY (InvoiceHeaderID)
REFERENCES InvoicesHeader (InvoiceHeaderID)
ON DELETE CASCADE
ON UPDATE CASCADE
However, when the last two lines are removed (ON DELETE CASCADE DELETE and ON UPDATE CASCADE) it runs fine. Does anyone know how to set the referential integrity properties in a module?
Thanks in advance, knot22