Suspending Code Until Outside Application Finished

EdFred

knows enough, dangerous
Local time
Today, 03:32
Joined
Mar 2, 2007
Messages
131
I have a Subroutine that is using CutePDF writer to create a PDF from a report, then attach it to a new message in outlook. The problem is the code runs too fast and it's looking for the file to attach before the file is created.

I'm getting
Run-time error '-2147024894 (80070002)':
Cannot find this file. Verify the path and file name are correct.

Yes, I know why I am getting the error, and yes I could use a loop timer, except it may be 5 seconds before the person finally clicks OK in CutePDF dialogue box, it may be 5 minutes or it may be 5 hours.

Or is that really my only option?

Thanks
 
Try to use stephen Lebans's PDF creator.
I use it for years.
 
By the way, I wanted to make sure you realized that beginning in 2007, PDF creation is native within Access. You can use OutputTo or SendObject among other methods. Previous to that I also used Leban's method.
 
By the way, I wanted to make sure you realized that beginning in 2007, PDF creation is native within Access. You can use OutputTo or SendObject among other methods. Previous to that I also used Leban's method.

I know that. But IIRC when using it it didn't remember where you saved your file to the last time. CutePDF does. Which makes it difficult to attach the file through automation. At least when I initially tried it that seemed to be the case. Maybe it was something else, but I knew there was a reason I didn't use it.
 
That could be, but it wouldn't be hard to duplicate. You could use any of the various file dialog methods to let the user browse to their desired location, and save that to a local table for later use. In any case, if you have a method you're comfortable with you can certainly stick with it. See if that shell and wait code does what you want.
 
That could be, but it wouldn't be hard to duplicate. You could use any of the various file dialog methods to let the user browse to their desired location, and save that to a local table for later use. In any case, if you have a method you're comfortable with you can certainly stick with it. See if that shell and wait code does what you want.

I will revisit OutputTo and give that a go. In the mean time I went with opening a form in dialogue mode on a 2 second delay which allows the Save as dialogue box to come up first.

Edit: Yeah, I just went with outputto and I'm in business. This also removes the user screwing things up by saving with the "wrong" file name.
 
Last edited:
Note that Stephen lebans code fails with A2010 and later, because the snp format is no longer supported

You can use this logic, tidied up.

If version >= 13 then
Docmd.ouputto etc
Else
Stephenlebans code
End if
 
You could also wait for the file to create

While dir(filespec)=""
Doevents
Wend
 

Users who are viewing this thread

Back
Top Bottom