Delete record with related records

buratti

Registered User.
Local time
Today, 09:01
Joined
Jul 8, 2009
Messages
234
I have a delete record button (slightly modified code copied form the northwind sample database) My form has an order details subform attached to it, and when i click my delete button it throws up an error, which I'm assuming is because its trying to delete the "parent" record and cannot due to the "child" record attached to it. If I have no Order Details data and click delete, it works just fine. What code can I add to it to delete the record attached to it also? My current code is:

Private Sub cmdDeleteOrder_Click()

If Me.NewRecord Then
If MsgBoxYesNo(CancelOrderPrompt) Then
Me.Undo
End If
Else
If IsNull(Me![Order ID]) Then
Beep
ElseIf Me![Status ID] = shipped_CustomerOrder Or Me![Status ID] = Closed_CustomerOrder Then
MsgBoxOKOnly CannotCancelShippedOrder
ElseIf MsgBoxYesNo(CancelOrderConfirmPrompt) Then
If CustomerOrders.Delete(Me![Order ID]) Then
MsgBoxOKOnly CancelOrderSuccess
eh.TryToCloseObject
Else
MsgBoxOKOnly CancelOrderFailure
End If
End If
End If
End Sub
 
I think it might be easier to look at your table relationships. Under "Edit Relationship" (By right clicking on the line joining the tables) make sure "cascade update related fields" and "cascade delete related records" are checked..... if both apply to your app.
 
do you have your cascading deletes turned on in the relationships manager?
 
I think that did it, thanks. I tried it on just one record so far, and no errors. Will let you know if there are problems on other records. Thanks!!
 

Users who are viewing this thread

Back
Top Bottom