VBA – 更新进度栏,同时运行SQL查询

我有一个进度条,根据行更新:

Call ProgressBar(X) 

其中X表示栏显示为“完成”的百分比。

我粗略地计算了整个代码中的各个时间间隔,并把线路放在了几个地方。 在大多数的代码中,它的运行非常顺利,只有一半的代码,问题被迫从10%跳到60%。

我正在使用ADODB连接在代码中运行SQL查询(我不能从代码中拿出来,因为我通过它传递variables)。 从10到60的跳转是执行查询的那一行的哪一侧

  Set rs = conn.Execute(QryND) 

其中rs定义为ADODB.Recordset,conn定义为ADODB.Connection。

我想理想的是,我会知道是否可以说:

  Call ProgressBar(10) 'code to the effect of: "in x seconds, execute the next line but in 'the meantime continue with the code Call ProgressBar(20) 'code to the effect of: "in 2x seconds, execute the line but in the 'meantime continue with the code Call ProgressBar(30) Set rs = conn.Execute(QryND) 

或者是这个效果

另外一种方法是在后台运行查询,然后继续执行代码。 例如

  Call ProgressBar(10) 'instruct to run in backrgound: Set rs = conn.Execute(QryND) Call ProgressBar(10) 'wait x seconds Call ProgressBar(20) 'wait x seconds . . . 'Stop running query in background (in case it hasn't finished) 

做这些听起来可能吗?

不build议运行后台查询,因为它们可能会将代码运行为错误。 你实际上可以做的就是把StatusBar放在f *上,并用while循环(或者定期)检查它,也就是说,它是获取连接,运行还是完成。
你可以做的是创build一个ActiveX对象来显示你想要告诉的任何东西,甚至高达加载条和多行反馈。
除非您调用外部脚本执行它们,否则在单线程应用程序中不能真正拥有asynchronous进程。