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
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