>
>Try adding a DOEVENTS after quit, and another after the copy. I think VFP simply fires off each line and doesn't wait for Windows events to process before proceeding. DOEVENTS will likely solve that.Well, the DOEVENTS looked hopeful, but does not seem to do the trick. I placed a DOEVENTS right after the QUIT and I still get a 'file access denied' when I subsequently try to erase the document I was working on.
The errant code has the following form
oword.quit(wdSaveChanges)
DOEVENTS
dosomeotherstuff
ERASE mytempfile
If I break on the quit line, then continue, I get the 'file access denied' error.
If I break on the DOEVENTS line (or any other line before the erase), the ERASE succeeds.
However, I was able to make things work the way I want them to by issueing a document.close prior to quitting (had to do this anyway due to suggestions in my other thread 'How to make sure word is gone'). So now I have
omydoc.close(wdSaveChanges)
DOEVENTS
if oword.documents.count < 1
oword.quit()
DOEVENTS
endif
<stuff>
ERASE mytempfile
This seems to work, but I don't really feel like I have positive control of the race condition; I've just separated the act of closing the document from the act of quitting word. This seems to give my code the time it needs before it issues the erase ... but seemingly as a side-effect rather than as a result of direct control.
Any other insight on how to make sure Word has released mytempfile before I try to erase it?
"The Iron Fish: The water is cold...but the fish don't mind"
...Jay Jenks, boyhood chum