vba 在访问表单中的消息框上单击“确定”时触发事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18367565/
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-11 22:53:48  来源:igfitidea点击:

Trigger an event on clicking "OK" on the messagebox in an access form

vbams-access

提问by user1403848

I have an access form in which after the user performs few operations a message box will appear. When the user clicks "OK" on the message box I want to close the current form and open a new form. How can I do this?

我有一个访问表单,在用户执行一些操作后,将出现一个消息框。当用户在消息框中单击“确定”时,我想关闭当前表单并打开一个新表单。我怎样才能做到这一点?

回答by Alan Waage

the VBA code execution is suspended until the user clicks ok. Therefore the next line of code after the msgbox call will be your spot to do the 'magic'

VBA 代码执行将暂停,直到用户单击确定。因此,在 msgbox 调用之后的下一行代码将是你施展“魔法”的地方

You want to open the new form first, then close the current form.

您想先打开新表单,然后关闭当前表单。

回答by Johnny Bones

You can either do it by just putting the code directly after the MsgBox command, or by checking the response of the user in a multi-response messagebox. For example:

您可以将代码直接放在 MsgBox 命令之后,或者通过在多响应消息框中检查用户的响应来实现。例如:

    If MsgBox("Do you really want to continue?" & vbCrLf, vbYesNo) = vbYes Then 
        DoCmd.Close MyFormName
    Else
        ...Perform some other function 
    End If 

This will pop up a messagebox with both Yes and No buttons, and allows you to run some alternate code if the response is No.

这将弹出一个带有 Yes 和 No 按钮的消息框,并允许您在响应为 No 时运行一些替代代码。