I have 2 tables, Orders and Order Details, the same as with the database Nortwindtraders shipped with Access. The table order is linked with the table Order
Details through the filed OrderID. It is autonumber in the table orders and number in the table Order Details.I have a very good function deleting a chosen order from a list box called ListOrders. This function is the following
Public Function CancelOrders()
Dim StrSQL As String
strSQL = “DELETE * FROM [order details] WHERE orderID = ” & frm!ListOrders & “;”
DoCmd.RunSQL strSQL
strSQL = “DELETE * FROM Orders WHERE orderID = ” & frm!ListOrders & “;”
DoCmd.RunSQL strSQL
End Function
I want to copy this function and accomodate it to other needs.The table order contains also the field PaymentID.I have made a new list boc called ListInvoices.
I have built the following function, based on the field PaymentID :
Public Function CancelInvoices()
Dim StrSQL As String
strSQL = “DELETE * FROM Orders WHERE PaymentID = ” & frm!ListInvoices & “;”
DoCmd.RunSQL strSQL
strSQL = “DELETE * FROM [order details] WHERE orderID = ” & frm!ListInvoices & “;”
DoCmd.RunSQL strSQL
End Function
This function does not work, it does not delete. I can see that the reason is that do not refer to the field OrderID, because this is the linking field.Also,the field
PaymentID does not exist in the table Order Details and therefore my second line makes no sense to me.If i can find a way to refer to this field also, may be my function might work.
I will be very grateful if somebody will help me.