tech on the net

MS Access: Delete a record using VBA code in Access 2003/XP/2000/97

Question: In Microsoft Access 2003/XP/2000/97, I've created a form and I want to delete the currently selected record. How do I delete the current record in the form?

Answer: In your Access form, you could create a button. On the Click event of this button, you could place the following code:

Private Sub Command1_Click()

   DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
   DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
   
End Sub

In this example, we've created a button called Command1. When the user clicks on this button, the record currently displayed in the form will be deleted.