【问题标题】:How can I delete a record (that is selected by mouse) from a datasheet using a Delete button On Click Event?如何使用单击事件上的删除按钮从数据表中删除记录(通过鼠标选择)?
【发布时间】:2018-09-07 14:41:44
【问题描述】:
我的表单名称是[Show Shipping History],子表单名称是[Shipment-History subform],其中有记录源指向表,名为“My-Shipping-History”。我在主窗体上有一个“Delete Rec”按钮,我想通过单击它来删除表“My-Shipping-History”中的选定记录。
有人可以告诉我如何实现这一目标吗?
【问题讨论】:
标签:
ms-access
vba
ms-access-2013
【解决方案1】:
你可以在按钮的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