嗨,大家好,我在vba上尝试了该代码,这给了我错误:
Private Sub Command102_Click()
If msgbox("are u sure", MsgBoxStyle.yesno, "Delete") = MsgBoxResult.Yes Then
Resume
msgbox ("deleted")
Else
msgbox ("canceld")
End If
DoCmd.RunCommand acCmdDeleteRecord
End Sub
VBA
无法理解此代码,因为它是为编写的VB.NET
。如果这是您第一次听说VB.NET
,请将其视为的扩展VBA
(这是一个过分的简化,我希望我不会因为撰写此类内容而感到失望:))。
在VBA
语法上,您将执行以下操作:
Private Sub Command102_Click()
If MsgBox(Prompt:="Are you sure?", Buttons:=vbYesNo, Title:="Delete") = vbYes Then
On Error Resume Next
DoCmd.RunCommand acCmdDeleteRecord
If Err.Number = 0 Then
MsgBox Prompt:="Deleted", Buttons:=vbOKOnly, Title:="Deleted"
Else
MsgBox Prompt:="There is no record to delete!", Buttons:=vbOKOnly, Title:="Error"
End If
Else
MsgBox Prompt:="Canceled", Buttons:=vbOKOnly, Title:="Canceled"
End If
End Sub
Resume
在这种情况下,您不需要。
也看一下这篇文章,它非常相似。
希望这可以帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句