Thursday, April 29, 2021

Timer function

Returns a Single representing the number of seconds elapsed since midnight.

Syntax

Timer

Remarks

In Microsoft Windows the Timer function returns fractional portions of a second. On the Macintosh, timer resolution is one second.

Query example

Expression

Results

SELECT Timer() AS SecondsPast FROM ProductSales GROUP BY Timer();

Returns the number of seconds elapsed since midnight based on the system time and displays in the column SecondsPast.

VBA example

Note: Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

This example uses the Timer function to pause the application. The example also uses DoEvents to yield to other processes during the pause.

Dim PauseTime, Start, Finish, TotalTime
If (MsgBox("Press Yes to pause for 5 seconds", _
4)) = vbYes Then
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
MsgBox "Paused for " & TotalTime & " seconds"
Else
End
End If

See Also

Choose the right date function

No comments:

Post a Comment