PDA

View Full Version : Solved: Help with pausing code



smilla
09-28-2004, 01:09 AM
Hello,

I'm need of some help please.

I have written a lot of code which opens a word template which has a macro that automatically runs when opened which merges a rtf.

This all works fine but my problem is, I have 15 merge documents to open which takes alot of time. Because of the way my code is written, it just runs one after another. This is causing an error in word because it can't cope with all the activity at one time.

Is there a way of pausing because the commands?

Your help would be appreciated.

Smilla

Jacob Hilderbrand
09-28-2004, 01:48 AM
This will stall for 1.5 seconds

Dim MyTimer As Double

MyTimer = Timer
Do
Loop While Timer - MyTimer < 1.5

smilla
09-28-2004, 06:56 AM
Thanks but just one question, if I want to run different code each time, do I put all the code underneath the DO statement?


DoCmd.OutputTo acOutputQuery, "qryCPACounty", acFormatRTF, "G:\LAIR\LAIRReports\CPACounty.rtf", False ' this outputs my query to rtf
DoCmd.OutputTo acOutputQuery, "qryCPADistrict", acFormatRTF, "G:\LAIR\LAIRReports\CPADistrict.rtf", False ' this outputs my query to rtf

stAppNameKP = "C:\Program Files\Microsoft Office2k\Office\winword.exe g:\LAIR\LairReports\KeyPart.doc" ' These are the separate merged document
'Call Shell(stAppNameKP, vbMinimizedFocus)
' run the mailmerge of LA Services District Report
stAppNameLAD = "C:\Program Files\Microsoft Office2k\Office\winword.exe g:\LAIR\LairReports\LADistrict.doc" ' These are the separate merged document
Call Shell(stAppNameLAD, vbMinimizedFocus)

for instance, I want to run the first line of code, then wait 20 seconds, then run the second line of code.

Any ideas?
Thanks

Steiner
09-28-2004, 07:43 AM
Another option would be to use the sleep-function:

Declare it once right in the beginning of the module you have your code in:



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



Now you can call it just using
Sleep 20000 right where you want your code to stop for 20 seconds.

By the way, is there a special reason why you open a new Word instance for each file?:confused:

Daniel

smilla
09-28-2004, 08:20 AM
Thanks but could you let me know where to put this Private Sub etc (sorry brain is over worked today!!!).

Much appreciated.
Smilla

Jacob Hilderbrand
09-28-2004, 02:17 PM
Put Steiner's code at the very top of you module (above the Sub).

As for my code just add it to your code whereever you want to pause.

'Do Something

MyTimer = Timer
Do
Loop While Timer - MyTimer < 20

'Do Something

MyTimer = Timer
Do
Loop While Timer - MyTimer < 20

johnske
09-28-2004, 05:42 PM
Hi smilla,

Another alternative (basically a variation of DRJs code) is to make pause a function...
Put the following code at the very top of your code, then whenever you want to pause your code, just write Pause 20 (or however many seconds you want to pause for)


Public StartTime, DelayInSeconds As Integer

Function Pause(DelayInSeconds)
'//this declares "Pause" to be a function that can be used in other subs in your project
StartTime = Timer
Do While Timer < StartTime + DelayInSeconds
DoEvents
Loop
End Function


John :bink:

Howard Kaikow
10-16-2004, 12:51 PM
Hello,

I'm need of some help please.

I have written a lot of code which opens a word template which has a macro that automatically runs when opened which merges a rtf.

This all works fine but my problem is, I have 15 merge documents to open which takes alot of time. Because of the way my code is written, it just runs one after another. This is causing an error in word because it can't cope with all the activity at one time.

Is there a way of pausing because the commands?

Your help would be appreciated.

SmillaOne soution is to put the code that does the merge in a Function and do not let the function return until it has done it's thing.

The function could be parameterized to udentifu which files to merge, then be called once for each merge, not returning until each is done.

I've not done much with Word's merge, but I would read up on this to verify, or not, the following. I find it difficult to believe that, subject to resource constraints on your system (memory and swap file), I should think that you could run a bunch of concurrent merges with no problem, at least in theory.

mdmackillop
10-17-2004, 03:39 PM
If I was to set up to run 15 merges, I would run the queries to create the rtf files, then open up a Word document, possibly with a userform interface and run the merges from Word. Unless you're going to carry out the merge, save/print the documents all from within access, this would seem a simpler solution.
MD