BofRossClan
Technical User
I am working on an sales/inventory program. I need to be able to stop the user from deleting inventory items in the Master Inventory that have matching sales transactions. I have placed a delete button next to the item in my inventory lookup form. This is the code I tried, and it didn't work. I created a table "MasterInventory Without Matching Transactions" to search from. I get an error message "You canceled the previous operation" when I run my code.
varCode = Me.ItemCode
Dim varResult As Variant
varResult = DLookup("[InvID]", "[MasterInventory Without Matching Transactions]", "invid = " & varCode)
If varResult Is Null Then
MsgBox ("Sales transanctions exist for this item. You cannot delete it")
Exit Sub
Else
DoCmd.RunSQL "DELETE MasterInventory.InvID FROM MasterInventory" & _
" WHERE invid = " & varCode
End If
varCode = Me.ItemCode
Dim varResult As Variant
varResult = DLookup("[InvID]", "[MasterInventory Without Matching Transactions]", "invid = " & varCode)
If varResult Is Null Then
MsgBox ("Sales transanctions exist for this item. You cannot delete it")
Exit Sub
Else
DoCmd.RunSQL "DELETE MasterInventory.InvID FROM MasterInventory" & _
" WHERE invid = " & varCode
End If