Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Timed Pause 1

Status
Not open for further replies.

PeasNCarrots

Programmer
Jun 22, 2004
73
US
What is the best way to add in a 30 sec pause between running functions?
 
you could try using the on Timer event, but you would need at have a variable to hold the number of times you have run the procedure so that you know which function to run each time.
 
Try this code. It uses a Windows API to "sleep" for a specified amount of time:

Private Declare Sub sapiSleep Lib "kernel32" _
Alias "Sleep" _
(ByVal dwMilliseconds As Long)

Sub Pause(Seconds As Double)
' Pause for a given number of seconds (expressed as a whole or decimal number)
' Input:
' Seconds = Number of seconds to pause (e.g. 1, 1.5, 3.25, etc.)
If Seconds > 0 Then
Call sapiSleep(Seconds * 1000)
End If
End Sub


[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
The first question PeasNCarrots is when you say 'pause', exactly what do you mean?

Do you mean to suspend the entire thread?

Do you want to allow the first function to continue to execute, but wait at least 30 seconds before calling the second function?

Does your program have anything else to do while you're waiting?

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I am using sendkeys to automate another application, but I don't want to send those keys before the program is completely open. So I was thinking to suspend the code for x seconds to allow the other application to completely open.
 
Don't forget to use the AppActivate instruction as you never know where SendKeys send the keystrokes.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Sounds like the Sleep API would work in that case since you're not waiting on anything within your own thread to happen.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I'm not sure if the code in this thread will work for me. I have a pop up form that opens and displays a message while delete and update queries execute in the background, then closes. Only it all happens so fast the pop up form simply flashes on the screen. How can I add a two second pause so the pop up form displays for two seconds before automatically closing?
 
jaaret,

You could use the sleep API mentioned above in the pop-up form's OnOpen event. After the 2-second pause, issue a Close command:
Code:
Private Sub Form_Open(Cancel As Integer)
    Pause 2
    DoCmd.Close
End Sub
The problem with this is your calling form's code will continue while the form is still popped up. If that's okay, this will work.

If you want to prevent more code from your calling form from executing after you've run the queries, place the Pause after your DoCmd.OpenForm and query executions and beore the DoCmd.Close command.

[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Okay, I'm close, but I don't understand where this code should live:

Private Declare Sub sapiSleep Lib "kernel32" _
Alias "Sleep" _
(ByVal dwMilliseconds As Long)

When I've pasted that code into either the form's VBA window or in a module it errors out - it tacks this code at the end of the previous Private Sub. What am I not understanding?
 
The sapiSleep coding should be put at the top of the class module - above all other subroutines and functions. The Pause function can be placed anywhere within the class module.

[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top