3

我在 Access 项目中有以下 VBA:

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

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

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

4

2 回答 2

4

对不起,伙计们,我刚刚找到了答案(其中一个是谷歌搜索一段时间,发布到 SO,然后立即找到答案):

DoCmd.OpenForm "Importing"
DoEvents
' Some CPU-intensive code
于 2012-10-01T16:15:48.830 回答
2

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

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

然后在您的代码中:

 DoCmd.OpenForm "Importing"
    Do While Not ISLoaded("Importing")
        DoEvents
    Loop
于 2012-10-01T16:26:46.853 回答