gpt4 book ai didi

vba - MS Access 中的进度条

转载 作者:行者123 更新时间:2023-12-03 11:07:57 24 4
gpt4 key购买 nike

我有一个在 Microsoft Access 2010 中运行的查询,它需要 30 多分钟才能正常运行。我想向最终用户展示查询的某些状态。进度条会很好但不是必需的。在执行查询期间, Access 似乎线程不畅并且锁定得很紧,从而否定了我尝试的任何更新。虽然我更愿意使用 VS 并编写自己的应用程序来执行此操作,但我不得不使用 Access。
我曾经从填充数据库的批处理脚本中运行它,但我希望它在 Access 中完全独立。具体来说,“查询”实际上是一个 VBA 脚本,它可以 ping 一系列主机。所以我不太关心优化时间本身,而只是让最终用户知道它没有被锁定。

最佳答案

我经常做这样的事情

Dim n As Long, db As DAO.Database, rs As DAO.Recordset

'Show the hour glass
DoCmd.Hourglass True

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT ...")

rs.MoveLast 'Needed to get the accurate number of records

'Show the progress bar
SysCmd acSysCmdInitMeter, "working...", rs.RecordCount

rs.MoveFirst
Do Until rs.EOF
'Do the work here ...

'Update the progress bar
n = n + 1
SysCmd acSysCmdUpdateMeter, n

'Keep the application responding (optional)
DoEvents

rs.MoveNext
Loop
rs.Close: Set rs = Nothing
db.Close: Set db = Nothing

'Remove the progress bar
SysCmd acSysCmdRemoveMeter

'Show the normal cursor again
DoCmd.Hourglass False

注意:当然,您必须以编程方式完成这项工作才能正常工作。您无法在 Access 中以代码或类似方式查看正在运行的查询。可能您可以将慢查询的工作分成更小的部分,以便有机会更新进度条。但你总是可以展示沙漏;这告诉用户正在发生某些事情。

关于vba - MS Access 中的进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11956834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com