When is file creation complete?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My code loops through a recordset and creates a PDF file from a report on
each pass. It is necessary to rename the file before the next loop. It
takes about 4-5 secs before file creation is finished.
The rename line will fail until the file creation is complete. Currently I
trap that error and Resume until it completes (indicating that the file has
been created and renamed). For some reason this does not work on all
platforms. Anybody know a better way to guarantee file creation is complete
before code proceeds? Thanks.
 
Use Timer (Example looks for Access 'Printing' Dialog Also)

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
ClassName As Any, ByVal AppCaption As Any) As Long
Public Declare Function IsWindow Lib "user32" (ByVal hWnd As Long) As
Boolean

Dim T As Double
Dim hWnd As Long
' .....
T = Timer
hWnd = FindWindow(0&,"Printing")
While IsWindow(hWnd)
VBA.DoEvents
Wend

Wait5:
VBA.Err.Clear
While Timer - T < 5
VBA.DoEvents
Wend
On Error Resume Next
Name ....
If VBA.Err.Number <> 0 Goto Wait5
'...


HtH

Pieter
 
That seems to work. Is there something I'm missing comparing my on error
resume until no error and your "if vba.err.number <>0 goto wait 5:" Just for
my education. Looks like the big difference is "doevents".
 
Basically nothing
No need to choke the system with trying to execute failing statements though
& DoEvents isn't really the hero, it's just a way to tell access to let
other processes run while I "hang around"

Pieter
 
Clyde said:
My code loops through a recordset and creates a PDF file from a report on
each pass. It is necessary to rename the file before the next loop. It
takes about 4-5 secs before file creation is finished.
The rename line will fail until the file creation is complete. Currently I
trap that error and Resume until it completes (indicating that the file has
been created and renamed). For some reason this does not work on all
platforms. Anybody know a better way to guarantee file creation is complete
before code proceeds? Thanks.

Instead of renaming files after you've created them, why can't you just
give each new file a different name?

I think, at least earlier, you could examine the filesize of files. If
it was larger than 0, it was created, if it was still 0, then it's not
yet finished.
 
Thanks for the info.
--
Clyde


Pieter Wijnen said:
Basically nothing
No need to choke the system with trying to execute failing statements though
& DoEvents isn't really the hero, it's just a way to tell access to let
other processes run while I "hang around"

Pieter
 
Thanks. The PDF printer can only be set for "path/filename". So the
report.pdf needs to be renamed with the client name. Could just email the
report but the problem would still exist... ie can't call the send email proc
until file creation is complete.
 
Back
Top