delete button

dazza

Registered User.
Local time
Today, 21:38
Joined
Mar 18, 2003
Messages
11
Hi
I have a form with a subform, and basically, I want 1 delete button that will remove the related records in the subform, aswell as the record in the main form.

However, whenever I try the wizard, it says it cannot delete because of the related records in the sub form. If i remove the records in sub form, 1 by 1, i can then use the delete button.

Please see the screenshot below, and try and help :)

Thanks

deletebutton.jpg


--
http://www.darrenpowles.net \\ brand new webcam & weblog
http://www.wirelesswales.net \\ bring wales on the right side of the divide
Where do I belong forever, in who's arms, the time and place?
 
Have your delete button run a delete query using the criteria from your form to delete the rows that appear in your subform, requery your subform, than delete the main record.
 
Hi, thanks for your reply.

I really haven't got a clue how to do that. Is there a wizard?

--
http://www.darrenpowles.net \\ brand new webcam & weblog
http://www.wirelesswales.net \\ bring wales on the right side of the divide
Where do I belong forever, in who's arms, the time and place?
 
I'm sure there's a better, simpler, more elegant answer, but until it comes along, you could add code to the button's OnClick event that will delete the related records. A couple questions for you:

Are you using, as I'm guessing you are, a link table between the students and courses tables?

Have you turned on cascade delete in the relationship between the students table and the linking table? That may solved your problem by itself, if your relationships are correct...

What is currently in the OnClick event for your "delete" button?

--Do-For-Now Mac

(Whoops - see, FoFa already suggested another alternative... Still, cascade delete is probably easiest if you use it carefully, IMHO)
 
>Are you using, as I'm guessing you are, a link table between the students and courses tables?

Yes.

>Have you turned on cascade delete in the relationship between the students table and the linking table?

No, but I'll try it now....


>That may solved your problem by itself, if your relationships are correct...

Indeed it did!! Thanks ever so much, so far so good!! :)


>What is currently in the OnClick event for your "delete" button?

I don't think that matters now :o)

Cheers!
--
http://www.darrenpowles.net \\ brand new webcam & weblog
http://www.wirelesswales.net \\ bring wales on the right side of the divide
Where do I belong forever, in who's arms, the time and place?
 
Glad you have it working--just be very, VERY careful with cascading deletes to make sure that you keep them within very specific limits. On your setup, for example, you wouldn't want to tell Access to delete a student and end up deleteing all the courses that they're registered for! That's why I wanted to make sure you had a proper linking-table setup.

Any other questions, just shout out.

--Cascading Mac
 

Users who are viewing this thread

Back
Top Bottom