Question : Delete from Access form certain records in a table that relate to another table's field

I have this in a command button in an Access form
What I am trying to do is delete any record from Table1 where the date is equal to the Date_Payment in the Dates_Worksheet table

DoCmd.RunSQL "DELETE FROM Table1 WHERE (Dates_Worksheet.Date_Payment) = Table1.PaymentDate"

Answer : Delete from Access form certain records in a table that relate to another table's field

Because dates in access stores info about hours, minutes and seconds (and maybe even milliseconds), if you want to delete records with only same date (year, month and day) try to restrict your query to this:

DELETE FROM Table1 WHERE
YEAR(Dates_Worksheet.Date_Payment) = YEAR(Table1.PaymentDate) AND
MONTH(Dates_Worksheet.Date_Payment) = MONTH(Table1.PaymentDate) AND
DAY(Dates_Worksheet.Date_Payment) = DAY(Table1.PaymentDate)

Hope that helps.
Random Solutions  
 
programming4us programming4us