Deleting Record from Multiple Tables

Jenaccess

Registered User.
Local time
Today, 04:07
Joined
Sep 8, 2010
Messages
67
Hi,

I'm running Access 2007. My database has four main tables:

tblStudent
tblAPR
tblService
tblStudentService

tblStudentService is a junction table between tblStudent and tblService. It has tblStudentServiceID as a PK and StudentID(pk of tblStudent) and ServiceID (pk of tblService) as foreign keys.

The problem I'm having is I want to put a delete button on my parent form, which is based on tblStudent. If the user clicks the button I want all the records from all four tables deleted. I've been using db.Execute commands to delete the data from the current record from all the tables in sequential order, child first then parent. This works on three out of the four tables, but no matter what I do I cannot get the records from tblService to delete.

This is the only table that does not have StudentID as either a primary or foreign key, I thought this would be resolved through the junction table. I think that's the issue, but I'm unsure how to resolve it. I don't want to have to manually go in and delete the data from tblService because it would defeat the purpose of the button. When my db.Execute didn't work, I tried a delete query but that didn't work either. I can't figure out what to do and would appreciate any ideas you'd be able to give me. Thank you!
 
Just add a boolean field to the Student table to Mark as Deleted. Change your queries to exclude the records related to students with that flag set.

It is easier and much safer than actually deleting records because they can be restored at any time. Queries can be easily made to Show Deleted if required.
 
Hi Galaxiom,

That's a great idea. I hadn't thought of it. Would you recommend this approach for duplicates as well?
 

Users who are viewing this thread

Back
Top Bottom