vba MS Access OpenForm acDialog 选项似乎不起作用

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

MS Access OpenForm acDialog option does not seem to work

formsvbams-accessaccess-vba

提问by gta0004

This

这个

DoCmd.OpenForm fnew, , , , , acDialog

Doesn't seem to stop code execution for some reason. Is it because I'm calling the function that has this method from another function and that is messing it up? E.g.

由于某种原因,似乎不会停止代码执行。是不是因为我正在从另一个函数调用具有此方法的函数并且将其搞砸了?例如

func1
<code>
Call func2
    <func2 code>
    DoCmd.OpenForm fnew, , , , , acDialog
<back to func1 code that executes even though i dont want it to until the form closes>

回答by HansUp

With acDialogas the OpenFormWindowModeparameter, your calling code should not continue until the form is closed.

随着acDialog作为OpenFormWindowMode参数,调用代码不应该继续下去,直到窗体关闭。

It should not matter that OpenFormtakes place in another procedure called from your code. In this example, when running func1, the MsgBoxis not displayed until the form closes.

OpenForm发生在从您的代码调用的另一个过程中应该无关紧要。在这个例子中,当运行时func1MsgBox直到窗体关闭才会显示 。

Public Function func1()
    Call func2
    MsgBox "form closed"
End Function

Public Function func2()
    'DoCmd.OpenForm "Form3", , , , , acDialog
    DoCmd.OpenForm "Form3", WindowMode:=acDialog
End Function

Note that code operates as described as long as the form is not already open. If it's open in Design View, calling OpenFormonly switches it to Form View without applying acDialog. If open in Form View, nothing happens, which means acDialogis not applied then either.

请注意,只要表单尚未打开,代码就会按照描述进行操作。如果它在设计视图中打开,调用OpenForm只会将其切换到表单视图而不应用acDialog. 如果在表单视图中打开,则不会发生任何事情,这意味着acDialog也不会应用。

If you want to guarantee that acDialogis applied, make sure the form is closed before calling OpenForm...

如果您想保证acDialog应用,请确保在调用之前关闭表单OpenForm...

Public Function func2()
    Const cstrForm As String = "Form3"
    If CurrentProject.AllForms(cstrForm).IsLoaded Then
        DoCmd.Close acForm, cstrForm
    End If
    'DoCmd.OpenForm cstrForm, , , , , acDialog
    DoCmd.OpenForm cstrForm, WindowMode:=acDialog
End Function

回答by user3760185

I struggled with this one for ages until I realised that the acDialog setting does nothing if the form is open in design view when the code is run. It does actually pause the code from the opening procedure when run in normal use (i.e. no one's trying to design anything). If you want to test this behaviour, create a form "zzTestForm", and run this from a module:

我在这个问题上挣扎了很长时间,直到我意识到如果在运行代码时在设计视图中打开表单,acDialog 设置将不起作用。在正常使用中运行时,它实际上会暂停打开过程中的代码(即没有人试图设计任何东西)。如果要测试此行为,请创建一个表单“zzTestForm”,然后从模块运行它:

Public Sub DoThis()

MsgBox "ok, let's go"

DoCmd.OpenForm "zzTestForm", acNormal, , , acFormPropertySettings, acDialog

MsgBox "you done yet?"

End Sub