Timer Function Example

You can use the Timer function to time operations and events in your Microsoft Access application by placing the Timer function immediately before and after the operation in your code that you wish to time. The following example uses the name of a query as its argument, then calculates how long it takes the query to run.

Sub QueryTimer (strQueryName As String)
    Dim sngStart As Single, sngEnd As Single
    Dim sngElapsed As Single

    sngStart = Timer                            ' Get start time.
    DoCmd.OpenQuery strQueryName, acNormal    ' Run query.
    sngEnd = Timer                                ' Get end time.
    sngElapsed = Format(sngEnd - sngStart, "Fixed")
    ' Elapsed time.
    MsgBox ("The query " & strQueryName & " took " & sngElapsed _
        & " seconds to run.")
End Sub