Deleting a form and deleting a record in another table

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Deleting a form and deleting a record in another table

Post by keiath »

Hi Guys

Am new here, and have a question.

I have form that is my 'purchase orders' this form as a sub form to input the orders that is recorded in and orders table, simple enough.

What I need is this, if I delete an order from the system (via a delete button) I need it to delete in the orders tables. How would I do that?

Thanks in Advance

User avatar
Wendell
4StarLounger
Posts: 482
Joined: 24 Jan 2010, 15:02
Location: Colorado, USA

Re: Deleting a form and deleting a record in another table

Post by Wendell »

Welcome to Eileen's Lounge - I think you will find this a friendly place for getting assistance with your Windows and Office issues.

If I understand correctly, you have a subform that displays individual orders that are related to a specific purchase order. If your subform is a bound subform (uses the orders table as it's data source), then you can delete an order from the subform by clicking on the record selection area on the left side of the subform. That is probably the simplest way. It is also possible to put a command button on the subform that will delete the record, but that involves doing some programming on the subform. If you want further assistance in that area, post the version of Access that you are using, and an indication of your experience with Access macros and VBA.
Wendell
You can't see the view if you don't climb the mountain!

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Deleting a form and deleting a record in another table

Post by keiath »

Hi thanks for that

The main form is called Purchase Orders and the subform is orders the subform is populated when I add lines to the sub form. the problem is when I delete a purchase order it is not deleting the corresponding order in the orders file. The 'orders' table is basicily a activity file that I then use in my stock control table that allows me to see each stock code and what has been order for that stock, so then showing me the stock and a 'total' of whats been ordered.

using access 2007 low level on marcos and vb

User avatar
HansV
Administrator
Posts: 78463
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Deleting a form and deleting a record in another table

Post by HansV »

The easiest way is to cascade delete related records. The screenshot below is from the Northwind sample database, and it shows a situation comparable to your database: a table tblOrders that is related to a table tblOrderDetails on the pkeyOrderID field.
x903.png
If you double-click the join line, the Edit Relationships dialog will be displayed. As you can see in the screenshot, the check box "Cascade Delete Related Records" has been ticked. This means that if you delete a record on the "one" side of the relationship, i.e. tblOrders, Access will delete all related records in the table on the "many" side of the relationship, i.e. tblOrderDetails. By default, Access will ask for permission to do so:
x904.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Deleting a form and deleting a record in another table

Post by keiath »

Thank you worked perfect