Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Filename to PDF Writer via code 2

Status
Not open for further replies.

timgill

IS-IT--Management
Feb 9, 2001
30
0
0
US
I have to generate reports for a list of source codes,a nd I want them output to separate PDF's. I have the code to the point where it will loop through the source codes, run the filtered report and pass the filename to the PDF writer. From there, I have to hit ENTER on the PDF writer dialog box to create the PDF, then do the same for the next and the next . . .

What I want is to let the program loop through them all automatically with no user intervention. Here's the problem:

I am using SendKeys to pass the filename, and my first thought was to add a chr(10) to the SendKeys line. That works for the first one, but when it loops to the second report, I get an error that it can't write to the device PDF Writer. I am guessing it is a timing problem. The PDF writer not having time to finish creating the file before Access tries to generate the next one.

Any ideas on how to do this? Has anyone tried something like this before?

Tim
 
You are correct that it is a timing problem. You need to create a function that creates a pause in your loop. I use the following

Function Wait(Delay As Integer)

Dim DelayEnd As Double
DoCmd.Hourglass 1
DelayEnd = DateAdd("s", Delay, Now)
While DateDiff("s", Now, DelayEnd) > 0
Wend
DoCmd.Hourglass False
End Function

You then call the function as Wait(10) for a ten second delay or Wait(45) etc.

You will need to experiment where to put the Wait() function in your loop and also how long to set it for.

I find creating PDFs is quite slow

Hope it helps

Jonathan
 
That did the trick. It actually only needed a 1 sec pause. I guess long enough for the PDFWriter to initialize.

Thanks! Tim Gill
Gill Consulting
 
I'm doing the same thing, however, I need to generate the filenames dynamically. For example, the first part of the filename will be built from an existing variable value.

Dim RPTDate as String
RPTDate = some calculation
SendKeys(RPTDate & "Remaining FileName.foo")

Any Ideas?
Thanks for your help!

Kenneth Frazier
 
Do a search on the internet for "ACG PDF and Mail Library". It will do exactly what you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top