MS Access - 暂停程序执行 [英] MS Access - Pause Program Execution

查看:35
本文介绍了MS Access - 暂停程序执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力寻找一种方法来暂停 Access 数据库中的内容.我发现了很多建议,其中一些有效,但不是我想要的方式.

I've been struggling trying to find a way to pause things in an Access database. I've found many suggestions and some of them work, but not the way I want.

我已经创建了一个小例子来看看我是否可以让它工作(然后我会在真正的程序中使用它).

I've created a mini-example to see if I can get it to work (then I'll use it in the real program).

有两种表单(Form1 和 Form2).当我单击 Form1 上的按钮时,它会关闭 Form 1 并打开 Form2.Form2 上有一个按钮,单击该按钮时可以执行我需要的操作(暂停 5 秒).这是我正在使用的代码....

There are two Forms (Form1 and Form2). When I click on a button on Form1 it closes Form 1 and opens Form2. There is a button on Form2 that when clicked on does do what I need (pauses for 5 seconds). Here is the code I'm using....

模块代码:

Sub WaitFor(NumOfSeconds As Long)

Dim SngSec As Long

SngSec = Timer + NumOfSeconds

Do While Timer < SngSec

DoEvents

Loop

End Sub

<小时>

命令按钮代码:


Command Button Code:

Call WaitFor(5)

  MsgBox "Waited for 5 seconds", vbOKOnly

DoCmd.Close

DoCmd.OpenForm "Form1", acNormal

<小时>

我需要在 Form2 上的按钮中运行代码,而无需用户单击它.我试过将该代码放入许多 Form 事件中,但没有运气,有点.取决于它进入的事件,它确实工作",但 Form2 实际上从未在屏幕上可见.


I need the code in the button on Form2 to run without a user needing to click on it. I've tried putting that code in a number of the Form events with no luck, sort of. Depending on which event it goes in it does "work" but Form2 is never actually visible on the screen.

我尝试从各种事件(加载、激活、当前、获得焦点)调用 Form2 上的命令按钮.当它起作用时,我仍然遇到 Form2 在屏幕上永远不可见的问题.

I've tried calling the Command Button on Form2 from various events (Load, Activate, Current, Got Focus). When it does work I still have the problem where Form2 is never visible on the screen.

有什么建议吗?(像 Visual Basic 这样的 Timer 控件会很好!)

Any suggestions? (A Timer control like Visual Basic has would be nice!)

推荐答案

不清楚是否要显示第二个表单,然后会出现一些延迟.您在打开/加载事件中放置的任何交易都将阻止显示表单,直到这两个启动"事件代码存根 100% 完成.

It not clear if you want the second form to show, and THEN have some delay occur. Any dealy you place in the on-open/on-load evet will prevent the form from display until AFTER these two "startup" event code stubs has 100% completed.

如果您想启动一个表单,然后延迟发生某些事情,那么您可以使用表单的计时器"事件——它很像 vb 或 vb.et.

If you looking to launch a form, and then have something occur with a delay, then you can use the forms "timer" event – it much like vb or vb.et.

所以说在 formB 打开后,你希望在 5 秒后一个 msgbox 显示hello",那么你可以使用以下代码:

So say after formB opens, you want after 5 seconds a msgbox to display "hello", then you would use the following code:

Private Sub Form_Timer()

   Me.TimerInterval = 0    ' turn off the timer event
                           ' so it fires only one time

   MsgBox "hello after 5 second delay"


End Sub

您还必须在保存表单之前(在设计模式下)将计时器间隔"设置为 5 秒(5000 毫秒).像这样:

You also just before you save the form (while in desing mode) have to set the timer "interval" to 5 seconds (5000 milisecs). Like this:

这篇关于MS Access - 暂停程序执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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