Question : MS Access SQL DELETE Query

I am trying to use this code to delete related records for a item in inventory if the item itself is removed.

Here's what I have for an On-Click event:

Dim SQL As String

If MsgBox("Are you sure you want to delete this item from inventory and all corresponding items?", vbYesNo) = vbYes Then

SQL = "DELETE DISTINCTROW [Equipment Inventory Main].* FROM [Equipment Inventory Main] RIGHT JOIN [Equipment Inventory] ON [Equipment Inventory Main].UIC = [Equipment Inventory].UIC"

SQL = "DELETE DISTINCTROW [Equipment Inventory Check InOut].* FROM [Equipment Inventory Check InOut] RIGHT JOIN [Equipment Inventory] ON [Equipment Inventory Check InOut].UIC = [Equipment Inventory].UIC"

SQL = "DELETE DISTINCTROW [Equipment Inventory Maintenance Log].* FROM [Equipment Inventory Maintenance Log] RIGHT JOIN [Equipment Inventory] ON [Equipment Inventory Maintenance Log].UIC = [Equipment Inventory].UIC"

    DoCmd.RunSQL SQL
Else

End If

The table EQUIPMENT INVENTORY is where the items are stored and the field UIC is the Unique Identifier Code that relates the item to the other tables. When I click on the button no errors come up but it doesn't delete anything. Any ideas?

Answer : MS Access SQL DELETE Query

A better idea would be to grab the ID, and feed it into your Delete query, instead of using a JOIN


SQL = "DELETE * FROM [Equipment Inventory Main] WHERE InventoryItem=" & Me.YourInventoryItemControl
DoCmd.RunSQL SQL

Random Solutions  
 
programming4us programming4us