Is there a way to force Access to pause execution for a specified
period of time ? I would like a command button on a form to run it's
code when clicked and then pause for 2 seconds before allowing any
other user input. Thank you for any help.
Wayne Gillespie - 05 Feb 2006 04:03 GMT
>Is there a way to force Access to pause execution for a specified
>period of time ? I would like a command button on a form to run it's
>code when clicked and then pause for 2 seconds before allowing any
>other user input. Thank you for any help.
Put the following into your code where you want the pause.
Dim T1 As Variant
Dim T2 As Variant
T1 = Now()
T2 = DateAdd("s", 2, T1)
Do Until T2 <= T1
T1 = Now()
Loop
Wayne Gillespie
Gosford NSW Australia
teddysnips@hotmail.com - 06 Feb 2006 15:49 GMT
> >Is there a way to force Access to pause execution for a specified
> >period of time ? I would like a command button on a form to run it's
[quoted text clipped - 12 lines]
> T1 = Now()
> Loop
If you're going to wait for an appreciable length of time, you might
want to put a DoEvents in the loop.
Edward
mike noel - 05 Feb 2006 04:09 GMT
You could use windows api stuff...
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
...
Sleep 2000
> Is there a way to force Access to pause execution for a specified
> period of time ? I would like a command button on a form to run it's
> code when clicked and then pause for 2 seconds before allowing any
> other user input. Thank you for any help.
Jeremy Wallace - 06 Feb 2006 18:04 GMT
I use Trevor Best's code:
Sub WaitFor(psngSeconds As Single)
' wait for specified number of seconds
' Copyright Trevor Best (tre...@besty.org.uk) <-OK, so I added
thisline.
Dim sngStart As Single
Dim sngET As Single
sngStart = Timer
DoEvents
Do While sngET < psngSeconds
DoEvents
' check for mighnight as the Timer() function will
' rollover at this point
sngET = Timer - sngStart
If sngET < 0 Then
' it rolled over - add number of seconds
' in a day
sngET = sngET + 86400
Beep
End If
' now don't hog the processor
' release some CPU slices back to Windoze
DoEvents
Loop
End Sub