如何使用“删除”按钮单击“事件”,从数据表中删除记录(通过鼠标选择)?

问题描述 投票:0回答:1

我的表单名称是[显示运输历史],子表单名称是[发货历史子表单],其记录源指向名为“My-Shipping-History”的表。我在主窗体上有一个“删除录制”按钮,我希望通过单击它从“我的航运历史”表中删除所选录制。谁能让我知道如何实现这一目标?

access-vba ms-access-2013
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.