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: