This example will delete a record on a form. To use this code, add a command button to a form and name it cmdDelete. Add the code to the OnClick event.
'***************** Code Start ******************* 'Code from Microsoft Knowledge Base Adapted by Terry Wickenden Private Sub cmdDelete_Click() On Error GoTo Err_cmdDelete_Click DoCmd.SetWarnings False If MsgBox("Confirm deletion of the record?", _ vbQuestion + vbYesNo + vbDefaultButton2, _ "Delete?") = vbYes Then DoCmd.RunCommand acCmdSelectRecord DoCmd.RunCommand acCmdDeleteRecord End If Exit_cmdDelete_Click: DoCmd.SetWarnings True Exit Sub Err_cmdDelete_Click: MsgBox Err.Description Resume Exit_cmdDelete_Click End Sub '****************** Code End ********************
Return to Example List