1

大家好,我在访问 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
4

1 回答 1

2

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在这种情况下。

也看看这个帖子,很相似。

希望这可以帮助!

于 2013-10-26T13:33:49.523 回答