MS Access OpenForm acDialog选项似乎不起作用 [英] MS Access OpenForm acDialog option does not seem to work

查看:59
本文介绍了MS Access OpenForm acDialog选项似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DoCmd.OpenForm fnew, , , , , acDialog

由于某种原因,似乎没有停止执行代码.是因为我要从另一个函数调用具有该方法的函数,并且搞砸了吗? 例如

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>

解决方案

使用acDialog作为OpenForm WindowMode 参数,在关闭表单之前,您的调用代码不应继续. >

OpenForm发生在您的代码中调用的另一个过程中无关紧要.在此示例中,运行func1时,直到窗体关闭,才会显示MsgBox.

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

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

请注意,只要表单尚未打开,代码就会按照描述的方式进行操作.如果它在设计视图中打开,则调用OpenForm只会将其切换到表单视图",而无需应用acDialog.如果在表单视图"中打开,则什么也不会发生,这意味着acDialog不会被应用.

如果要保证已应用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
 

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>

解决方案

With acDialog as the OpenForm WindowMode parameter, your calling code should not continue until the form is closed.

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

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 OpenForm only switches it to Form View without applying acDialog. If open in Form View, nothing happens, which means acDialog is not applied then either.

If you want to guarantee that acDialog is applied, make sure the form is closed before calling 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

这篇关于MS Access OpenForm acDialog选项似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆