如何使用单击事件上的删除按钮从数据表中删除记录(由鼠标选择)?

How can I delete a record (that is selected by mouse) from a datasheet using a Delete button On Click Event?

我的表单名称是[Show Shipping History],子表单名称是[Shipment-History subform],它有记录源指向Table,叫做“My-Shipping-History”。我在主窗体上有一个“删除记录”按钮,我想通过单击它从 table“我的运输历史”中删除选定的记录。 有人可以告诉我如何实现这一目标吗?

您可以在按钮的 OnClick 事件中插入此代码:

Dim fm As Form
Dim rs As DAO.Recordset

Set fm = Me!NameOfYourSubformCONTROL.Form
Set rs = fm.RecordsetClone

If rs.RecordCount > 0 Then
    ' Move to the current record of the subform.
    rs.Bookmark = frm.Bookmark
    ' Delete the record.
    rs.Delete
    rs.Close
End If