Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Create a Function That Pauses Program Execution


View products that this article applies to.

This article was previously published under Q210182
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

↑ Back to the top


Summary

This article shows you how to create a sample user-defined function called Wait(), which you can use to delay program execution for a specified period of time. You can call this function from any form or report event procedure or from a RunCode macro action.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

↑ Back to the top


More information

To create the sample user-defined Wait() function, open a new module and enter the following code:
'**********************************************************
   ' Declarations section of the module
'**********************************************************

Option Explicit

'===================================================================
' NOTE: In Visual Basic for Applications the unit of greatest precision
' is seconds. Therefore if the Timer is set to wait one second, the
' result could be a delay of anywhere from 0 to 1 second. If a higher
' degree of precision is required, another option is to use the Timer
' event of the form which has the ability to trigger every 1000th of a
' second.
'====================================================================

Function Wait (Delay As Integer, DispHrglass As Integer)

Dim DelayEnd As Double
DoCmd.Hourglass DispHrglass

DelayEnd = DateAdd("s", Delay, Now)
While DateDiff("s", Now, DelayEnd) > 0
Wend
DoCmd.Hourglass False

End Function

				
To test this function, type the following line in the Immediate Window, and then press ENTER:
?Wait(5,1)
				

↑ Back to the top


Keywords: KB210182, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 210182
Revision : 5
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 412