VBA 等到表单打开

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

VBA Wait until form open

vbams-accessms-access-2007access-vba

提问by Danny Beckett

I have the following VBA in an Access project:

我在 Access 项目中有以下 VBA:

DoCmd.OpenForm "Importing"
' Some CPU-intensive code

The problem is, I just get a white screen until the intensive part is done.

问题是,在密集部分完成之前,我只会得到一个白屏。

How can I wait until the form is open before executing the rest of the code?

如何在执行其余代码之前等到表单打开?

回答by Danny Beckett

Sorry for the question guys, I've just found the answer (one of them cases of Googling for a while, posting to SO, and finding the answer right after):

抱歉,我刚刚找到了答案(其中一个是谷歌搜索一段时间,发布到 SO,然后立即找到答案):

DoCmd.OpenForm "Importing"
DoEvents
' Some CPU-intensive code

回答by Daniel

Just for completeness sake, you could also use the following function I can't remember where I got it from, but I didn't write it:

为了完整起见,您还可以使用以下函数我不记得我从哪里得到它,但我没有写它:

Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.
' Use form name according to Access, not VBA.
' Only works for Access
    Dim oAccessObject As AccessObject

    Set oAccessObject = CurrentProject.AllForms(strFormName)
    If oAccessObject.IsLoaded Then
        If oAccessObject.CurrentView <> acCurViewDesign Then
            IsLoaded = True
        End If
    End If

End Function

Then in your code:

然后在你的代码中:

 DoCmd.OpenForm "Importing"
    Do While Not ISLoaded("Importing")
        DoEvents
    Loop