对MS Access进行收益控制以更新gui和处理表单事件 [英] Yield control to MS Access to update gui and process form events

查看:64
本文介绍了对MS Access进行收益控制以更新gui和处理表单事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MS Access中使用VBA来选择数据并将其从表中馈送到Web服务.数据是按块发送的,因此xmlhttprequest的执行时间很短.由于脚本是在gui线程中运行的,因此在上传过程中,Access不再负责,并且表单也不会更新.

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

推荐答案

尝试添加 DoEvents 声明"放弃执行宏,以便操作系统可以处理其他事件".

这篇关于对MS Access进行收益控制以更新gui和处理表单事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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