Yield control to MS Access to update gui and process form events

送分小仙女□ 提交于 2019-12-25 05:07:26

问题


I am using VBA in MS Access to select and feed data from table to web service. Data is send in chunks, so xmlhttprequest execution time is quite short. Because script is run in gui thread, during upload Access becomes non-responsible and form does not update.

How can I yield control, so form contents can be updated and have some responsiveness.

Private Sub do_stuff()
    lblOperation.Caption = "Doing stuff"
    lblProgress.Caption = "0"

    Dim rs As Recordset
    Dim chunk As String

    ' ... make query ...

    Do While Not rs.EOF
        ' ... collect data to be sent ...
        rs.MoveNext

        n = n + 1
        If n > 50 Or rs.EOF Then
            ' send chunk
            lblProgress.Caption = "Doing progress..."
            send_chunk(chunk)

            ' Give Access control, so it can pump messages and update form
            ' Something like Application.ProcessMessages in delphi

            chunk = ""
            n = 0
        End If
    Loop
    rs.Close
End Sub

回答1:


Try adding a DoEvents statement which "surrenders execution of the macro so that the operating system can process other events".



来源:https://stackoverflow.com/questions/6584046/yield-control-to-ms-access-to-update-gui-and-process-form-events

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!