
How to Trap Cascade Delete Errors from Jet Engine
Hello Dave
I browsed this newsgroup and camed to your mail.
I also had this problem. I have a database with a table named Person where
I register adress information about persons. I also have a lot of tables
that are connected to this and like you, I wanted to know if a perticular
person had any connections before I deleted his/her record from the
database.
Instead of detecting related records when I try to delete the record I have
included a subform in my form named "Person" where I display all current
connections. The data source for the subform is a union query:
SELECT "Name of form - Table1" AS Table FROM Table1 WHERE PersID =
Forms!Person!PersID
UNION
SELECT "Name of form - Table2" AS Table FROM Table2 WHERE PersID =
Forms!Person!PersID
UNION
SELECT .....and so on ....;
The primary key in my Person table i displayed in the control
Forms!Person!PersID and the forrein key in the other tables are all called
PersID. There shall be one UNION SELECT for each relation to your table.
This will list all your connections. If there is a connection to Table1 the
text "Name of form - Table1" will be displayed in the subform.
This is maybe not exactly what you were asking for and maybe a different
approch, but it works fine for me.
Hope this will be of some help
Lars Fransn
Quote:
> I am looking for a way to tell wether there are any related records in
> other tables to the current record before I delete it. If you do not
> have cascade delete turned on, the Jet Engine will stop you from deleting
> the
> current record if you have related records. I need to be able to
> intercept that message from the Jet engine and execute some code, but it
> does not
> generate an error condition.
> I am fairly good at writing code and am working on a routine that looks
up
> all the
> relationships via DAO and then checks each table for the current ID. But
> if I could just trap
> the message from Jet engine, it would save a lot of time.
> Anybody got ideas? Thanks.