访问VBA循环(无响应) [英] Access VBA Loop (Not Responding)

查看:450
本文介绍了访问VBA循环(无响应)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遍历一个记录集以执行一些基本功能或编辑。

I am looping through a recordset to carry out some basic functions or edits.

通常,对于具有50个以上记录的记录集,访问将停止响应。

Usually with recordsets with more than 50 records, access will stop responding.

在执行循环命令之前,我有 me.repaint ,但是窗口始终冻结并且访问标题栏显示:。 ..(不响应)。

I have me.repaint before the loop command but the window always freezes and the access title bar shows: ...(Not Responding).

有什么办法解决这个问题吗?

Any idea how to get around this?

谢谢。

戴夫。

编辑:添加了循环代码

If Me.Dirty = True Then Me.Dirty = False
Dim rs As DAO.Recordset
Set rs = Me.Guardians_Subform1.Form.Recordset

Dim strFirstName, strLastName As String

If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst 

    Do Until rs.EOF = True     
rs.Edit
    strFirstName = Trim(StrConv(rs!FirstName, 3))
    strLastName = Trim(StrConv(rs!LastName, 3))
    If rs!FirstName <> strFirstName Then
    rs!FirstName = strFirstName
    End If

    If rs!LastName <> strLastName Then
    rs!LastName = strLastName
    End If

     rs.Update
       rs.MoveNext
Me.Repaint
    Loop  
Else
    MsgBox "There are no records in the recordset."
End If
Set rs = Nothing 


推荐答案

您需要在内部调用 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.

这篇关于访问VBA循环(无响应)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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