PDA

View Full Version : Pausing between code



smilla
09-08-2004, 01:41 AM
Hi there,

Can anybody tell me how to write some code to pause in between other code.

I have written some code to open a word document, merges with 100 records (takes 4 minutes) then opens another word document, merges again etc etc. I have 15 word documents and if the code run one after another, I am getting all sorts of errors through word.

I want to be able to pause: 50000 (i.e. 5 minutes) then run next code.

Any ideas would be appreciated.

Smilla

___
09-08-2004, 01:54 AM
Try using this function (Code by G.Hudson)

Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Err_Pause


Dim PauseTime As Variant, Start As Variant

PauseTime = NumberOfSeconds
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop

Exit_Pause:
Exit Function

Err_Pause:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Pause

End Function


and call it like...
Pause (5)
for a five second pause.

HTH

Jacob Hilderbrand
09-08-2004, 02:03 AM
Application.Wait Now + TimeSerial(0, 5, 0)


Also check out Application.OnTime

{Edit} I didn't realize this was for Access. Disregard.

Daniel Klann
09-08-2004, 11:20 PM
Application.Wait Now + TimeSerial(0, 5, 0)



Also check out Application.OnTime
DRJ, they are Excel methods and aren't available in Access.

Regards,
Daniel

ALaRiva
09-09-2004, 09:22 AM
Or you can try this Sleep API:


Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilleseconds As Long)


Then call it like this

Sleep 5000

HTH, Thanks.