本文介绍了MS Access中的进度栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Microsoft Access 2010中运行查询,正常运行需要30分钟以上.我想向最终用户显示查询的某些状态.进度条会很好,但不是必需的.在执行查询期间,访问权限似乎线程不足,并且锁得很紧,否定了我尝试的所有更新.虽然我宁愿使用VS并编写自己的应用程序来执行此操作,但我还是不得不使用Access.

I have a query running in Microsoft Access 2010 and it takes over 30 minutes to run normally. I would like to present the end user with some status of the query. A progress bar would be nice but not required. Access seems to be poorly threaded and locks up tight during the execution of the query, negating any updates I try. While I'd rather whip out VS and write my own app to do this, I'm forced to use Access.

有什么想法吗?

编辑

我以前是从填充数据库的批处理脚本中运行此脚本的,但是我希望所有这些元素都可以在Access中自包含.具体来说,查询"实际上是对一系列主机执行ping操作的VBA脚本.因此,我不太在意优化时间本身,而只是在让最终用户知道它没有锁定时间.

I used to run this from a batch script which populated the database but I'd like to have it all self-contained in Access. To be specific, the "query" is really a VBA script that pings a series of hosts. So I'm not too concerned about optimizing the time per se but simply about letting the end user know it hasn't locked up.

推荐答案

我经常做这样的事情

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中的代码等中观看敲打查询.可能您可以将慢速查询的工作分成较小的部分,以便有机会更新进度条.但是您总是可以显示沙漏;这告诉用户发生了什么事.

Note: Of course you must do the work programmatically for this to work. You cannot watch a runnging query in code or the like in Access. Possibly you could split the work of your slow query into smaller pieces, in order to get the chance of updating a progress bar. But you can always show the hour glass; this tells the user that something is happening.

这篇关于MS Access中的进度栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:20
查看更多