VBA等到表格打开

时间:2012-10-01 16:13:38

标签: vba ms-access ms-access-2007 access-vba

我在Access项目中有以下VBA:

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

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

在执行剩下的代码之前,我怎么能等到表单打开?

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分: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