如何在访问 vba 中运行进程时弹出“请稍候”消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22259919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pop up "Please Wait" message while running a process in access vba
提问by vuyy1182
I have a button in my access form ,when clicks it checks some code to find data in excel cells. It is taking a while to finish the process. By that time i need to display Please wait message to users.
我的访问表单中有一个按钮,单击时它会检查一些代码以在 excel 单元格中查找数据。完成这个过程需要一段时间。到那时我需要向用户显示请等待消息。
I'm calling this method, but not working
我正在调用此方法,但不起作用
Sub plswaitmsg()
Dim statusmsg As Variant
statusmsg = SysCmd(acSysCmdRemoveMeter)
statusmsg = SysCmd(acSysCmdSetStatus, "Loading dropdown data,please wait.")
End Sub
回答by RubberDuck
You could use this status bar in execution mode. http://christopherjmcclellan.wordpress.com/2014/03/08/progress-bar-for-ms-access/
您可以在执行模式下使用此状态栏。 http://christopherjmcclellan.wordpress.com/2014/03/08/progress-bar-for-ms-access/
It's a bit much to post here in it's entirety, but it relies on two big things. The first is that you can create a new instance of any form on the fly in your code. This hinges on the fact that Access forms are really just glorified class modules. You can try it yourself by saving a new form with the default name "Form1", and then placing this code in a regular *.bas module.
在这里发布全文有点多,但它依赖于两件大事。第一个是您可以在代码中动态创建任何表单的新实例。这取决于 Access 表单实际上只是美化的类模块这一事实。您可以自己尝试使用默认名称“Form1”保存一个新表单,然后将此代码放入常规 *.bas 模块中。
Sub ShowForm()
Dim frm as New Form_Form1
frm.Visible = True
Stop
End Sub
Note that I put a breakpoint in because the form will auto-destruct when it goes out of scope.
请注意,我放置了一个断点,因为表单在超出范围时会自动销毁。
The second big thing is using DoEvents
to give the OS enough time to repaint the screen.
第二件大事是使用DoEvents
给操作系统足够的时间来重新绘制屏幕。
Understanding these two things, you should be able to design a form with a textbox that changes size as your process runs. Also, I would actually recommend a UserForm instead of an Access Form. I didn't know it at the time, but you can use UserForms not just in Excel, but also in Access.
了解这两件事后,您应该能够设计一个带有文本框的表单,该文本框会随着流程运行而改变大小。此外,我实际上会推荐用户表单而不是访问表单。我当时不知道,但您不仅可以在 Excel 中使用用户窗体,还可以在 Access 中使用。
回答by Steven Martin
You cant display a MsgBox in Excel without pausing execution of the marco. You should use the Status Bar to display the message
您不能在不暂停执行宏的情况下在 Excel 中显示 MsgBox。您应该使用状态栏来显示消息
Application.StatusBar = "Please be patient..."
then to clear it
然后清除它
Application.StatusBar = False
回答by Yelay
Here is a very easy way:
这是一个非常简单的方法:
The true process ending time is latest code line.
真正的进程结束时间是最新的代码行。
- So you put finish massage as label caption above end sub code line.
- Then wait massage label caption should be before processing.
- Your command button can then use "please wait"message in mouse down input instead click input.
- 因此,您将完成按摩作为结束子代码行上方的标签标题。
- 然后等待按摩标签标题应该在处理之前。
- 然后,您的命令按钮可以在鼠标按下输入中使用“请稍候”消息,而不是单击输入。