访问删除记录的 VBA 代码不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19606029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access VBA code that delete records not working
提问by Alaa Eldin
hi guys i tried that code on access vba and it giving me error here is it :
嗨,伙计们,我在访问 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
回答by Ioannis
VBA
does not understand this code because it is written for VB.NET
. If it is the first time you hear about VB.NET
, think of it as an extension of VBA
(this is a huge oversimplification and I hope I dont get downvoted because of writing such stuff :) ).
VBA
不理解此代码,因为它是为VB.NET
. 如果这是您第一次听说VB.NET
,请将其视为VBA
(这是一个巨大的过度简化,我希望我不会因为编写此类内容而被低估:))。
In VBA
syntax you would do something like:
在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
You do not need Resume
in this context.
你不需要Resume
在这种情况下。
Have a look at this postas well, it is quite similar.
也看看这个帖子,它非常相似。
Hope this helps!
希望这可以帮助!