且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

访问VBA循环(无响应)

更新时间:2023-11-04 12:37:16

您需要在内部调用 DoEvents-Function 循环将控制权传递给操作系统,以重绘您的Access-GUI并处理可能需要处理的任何其他Window-Message。这样,该应用程序就不会在任务管理器和标题栏中标记为不响应。

You need to call the DoEvents-Function within the loop to pass control to the operating system to redraw your Access-GUI and to process any other Window-Messages that might need processing. By that the application will not be marked as "Not responding" in the Task Manager and the Title Bar.

Do Until rs.EOF = True
  [...]
  rs.MoveNext
  DoEvents
Loop  

有一个小的性能折衷。如果不调用DoEvents,则循环的总执行时间会短一些,但是Access不会执行其他任何操作,然后处理您的循环。因此,它似乎没有响应。

There is a small performance trade off. If not calling DoEvents, the total execution time for the loop will be a little shorter, but Access will do nothing else then process your loop. Therefore it seems to be not responding.