访问删除记录的 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:04:50  来源:igfitidea点击:

Access VBA code that delete records not working

vbaaccess-vba

提问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

VBAdoes 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 VBAsyntax 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 Resumein this context.

你不需要Resume在这种情况下。

Have a look at this postas well, it is quite similar.

也看看这个帖子,它非常相似。

Hope this helps!

希望这可以帮助!