Code Examples

Delete A Record

acCmdDeleteRecord, acCmdSelectRecord

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.

You could replace acCmdDeleteRecord with acCmdDelete.

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

© 1998 - 2011 Terry Wickenden TKW Design Site developed maintained and hosted by TKW Design. This site is best viewed at 1024 x 768. Optimised for Firefox.