供参考:
点击下载此附件
【初级入门】主窗体、子窗体如何共用一个删除按钮示例[Access软件网]
http://www.accessoft.com/article-show.asp?id=8991
Private Sub Command37_Click()
Dim ctl As Control
Set ctl = Screen.PreviousControl
If ctl.Name = "合约细项" Then
strsql = "DELETE * FROM 合约细项 WHERE (((合约细项.IID)=[Forms]![对包商合约]![合约细项].[Form]![IID]));"
DoCmd.SetWarnings False ' 取消系统提示
DoCmd.RunSQL strsql ' 运行查询
DoCmd.SetWarnings True ' 恢复系统提示
Me.合约细项.Requery
MsgBox "成功删除子窗体记录."
Else
strsql = "DELETE * FROM 合约 WHERE (((合约.BID_NO)=[Forms]![对包商合约]![BID_NO]));"
DoCmd.SetWarnings False ' 取消系统提示
DoCmd.RunSQL strsql ' 运行查询
DoCmd.SetWarnings True ' 恢复系统提示
Me.Requery
MsgBox "成功删除主窗体记录."
End If
End Sub