Delete records from 2 different tables

I have 2 tables item_cat_subcat which contains ITEMNMBR, CAT_ID, and SUBCAT_ID which will contain 1 record with that ITEMNMBR  and item_attrib_attribvl which contains  ITEMNMBR, ATTRIB_ID, and ATTRBVLU_ID which could contain multiple  ITEMNMBR  values. I also have a form frmAssignedItems based on a query (See Image) that displays the records in those tables. and a delete button next to each record on the form, I want to be able to delete the records from both tables based on the ITEMNMBR  on the form with VBA.
Access-Query.jpg
skull52Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PatHartmanCommented:
1. Define primary keys for all tables.
2. Create Referential Integrity using the relationships dialog.
3. Specify cascade delete on relationships where you want deletes to be propagated.

Based on the joins shown in the diagram, item_cat_subcat is the parent table to TWO child tables.  If you want the delete to work on the parent record, then Cascade Delete must be defined on both of these relationships.

Otherwise, you're on your own and will need to run separate delete queries on all tables that you want to delete from.
0
skull52Author Commented:
Pat, the only tables that i want the records deleted are item_cat_subcat and item_attrib_attribvl
0
skull52Author Commented:
<Otherwise, you're on your own and will need to run separate delete queries on all tables that you want to delete from.> I don't necessarily have a problem with doing that as it is only the 2 tables, so how would I do that
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

PatHartmanCommented:
Use the QBE to build the query.  The criteria can reference the form field.  Intellisense will help you build it.

Delete * from sometable Where somefield = Forms!yourform!yourfield;

Then you can use DoCmd.OpenQuery to run each query.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skull52Author Commented:
Pat, thanks I was able to do what I wanted by creating queries as you suggested.
0
PatHartmanCommented:
You're welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.