如何让VBA等待查询完成? [英] How do you make a VBA wait for a query to finish?

查看:119
本文介绍了如何让VBA等待查询完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

冒着过度简化我的情况的风险,以下是基本事实:


*我正在写一个ACCESS 2002 VBA。


*我的VBA自动使用一个表(表A)中的信息通过SQL重复查询第二个表(表B)。


*表A中的每条记录(大约有800条记录)表示查询表B的一组条件。


* VBA分析表B的查询返回的记录集,并在转移到表A中的下一条记录并再次查询表B之前将结果写回表A.


*正在查询的表(表B)有大约65,000条记录,因此查询需要几秒钟。


*问题是我的VBA代码在表B的查询之前继续执行完了。因此,表B中得到的记录集不完整,对它的分析产生了不准确的结果。


如何告诉Access(或VB)等待表B的查询到在继续使用剩下的代码之前完成了吗?


非常感谢任何帮助。

Scott

At the risk of oversimplifying my situation, here are the basic facts:

* I''m writing an ACCESS 2002 VBA.

* My VBA automatically uses information in one table (Table A) to repeatedly query a second table (Table B) via SQL.

* Each record in Table A (which has about 800 records) represents a set of conditions by which to query Table B.

* The VBA analyzes the recordset returned by the query of Table B, and writes the results back into Table A before moving to the next record in Table A and querying Table B again.

* The table being queried (Table B) has about 65,000 records, so the query takes a few seconds.

* The problem is that my VBA code continues to execute before the query of Table B is finished. Consequently, the resulting recordset from Table B it is incomplete and the analysis of it produces inaccurate results.

How do I tell Access (or VB) to wait for the query of Table B to finish before continuing with the rest of the code?

Any assistance is greatly appreciated.
Scott

推荐答案

把它放在声明部分:

Put this in declaration section:

展开 | 选择 | Wrap | 行号


我知道它已经有一段时间了但我只是碰到了这篇文章我应该发布一些可能更符合您情况的东西。


DBEngine.Idle dbRefreshCache


从帮助中复制的示例file:
I know it''s been a while yet I just ran across this article and thought I would post something that may be a little more appropriate for your circumstances.

DBEngine.Idle dbRefreshCache

An example copied from the help file:
展开 | 选择 | Wrap | 行号



我知道它已经有一段时间了但我只是碰到了这篇文章,并认为我会发布一些可能更适合你情况的东西。


DBEngine.Idle dbRefreshCache


复制的示例在帮助文件中:
I know it''s been a while yet I just ran across this article and thought I would post something that may be a little more appropriate for your circumstances.

DBEngine.Idle dbRefreshCache

An example copied from the help file:
展开 | 选择 | Wrap | 行号


这篇关于如何让VBA等待查询完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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