Question : Delete a record in the BeforeUpdate

How can I delete a record in the BeforeUpdate here is the code I use


Private Sub Form_BeforeUpdate(Cancel As Integer)

        If IsNull(CustomerID) Then
            If MsgBox("You cant go to this control" & vbNewLine & "You have to select a customer" & _
                vbNewLine & "Do you want do delete this record?", 16 + 4, "Cant Go To Control") = 6 Then

                CustomerID = DLookup("[CustomerID]", "[Customers]")

'Here I have to put some code to save the record so I should be able to delete it in the next line
               
                DoCmd.RunCommand acCmdDeleteRecord
            End If
            DoCmd.CancelEvent
        End If
End Sub
       

Answer : Delete a record in the BeforeUpdate

which record do u want to delete? the one just added?

why not try Me.Undo

also u dont need to do DoCmd.CancelEvent

setting cancel = true will not do the update


Random Solutions  
 
programming4us programming4us