Delete records in one table that relates to another table

Disto

New member
Local time
Today, 23:06
Joined
Sep 16, 2015
Messages
1
Hi there, I am new to this forum, hoping for some help.
I have attached a few simple data.
As you see I have two simple tables: "Tbl_Finances" and "Tbl_Periods".
Have also created a Delete-query: "Qry_Delete_Finances" that with criteria applying to both tables selects 10 of 26 records from "Tbl_Finances", so far so good.
The intention is to delete the 10 records from "Tbl_Finances", but not delete any records from "Tbl_Periods".
But when running "Qry_Delete_Finances", I get the error message: "Specify the table containing the records you want to delete".
I have tried and tried, and searched the web, but can't find how to "specify the table", can someone help out?
Obviously I need to work the solution into a bigger context, so pls explain the steps if appropriate.
Best regards
Disto :banghead: :)
 

Attachments

You do realize that neither table has a primary key defined?
And since the Tbl_Finances doesn't have a primary key, how would the code know which record to delete?
It would help me if I understood what these fields are. And some explanation of what you're trying to accomplish, not just that you want to delete 10 records.
 
DELETE Tbl_Periods.*
FROM Tbl_Periods
WHERE (Tbl_Periods.YtdYtg="YTG") AND tbl_Periods.Months In ( Select [Month] From tbl_Finances Where [Month] = tbl_Periods.Months And [Version]="Actuals_2015-16");
 
@arnelgp - records should be deleted from "Tbl_Finances", not "Tbl_Periods"
 
sorry, just human!

DELETE tbl_Finances.*, tbl_Finances.[Version], tbl_Finances.[Month]
FROM tbl_Finances
WHERE (((tbl_Finances.[Version])="Actuals_2015-16") AND ((tbl_Finances.[Month]) In (Select [Months] From Tbl_Periods Where [Months] = tbl_Finances.[Month]
And [YtdYtg] = "YTG")));
 

Users who are viewing this thread

Back
Top Bottom