Unanswered: Export reports to pdf - multiple files
I have large SQL Server database (many tables) that has to go to multiple reports, pdf files, different filenames generated by field from the database table.
Macros cannot do the job, of course. I started with VB.
Made connection string.
I made loop that can choose (for example) cities for pdf filenames (which I take from a table).
For each city it has to make a single report and send it to a pdf file.
Making report is not so complicated, but - how to send it to a pdf printer (one of printers from the list of printers, without a must to configure (for example) cutepdf as a default printer), and how to send the filename for it?
I have had a similar issue once. The way I found to do this in Access is to change the default printer to the pdf printer (I think I did this in a bat file because I couldn't find a way to do it in VBA) and when you do the export of the file make the file name a variable.
I can't seem to find the code right now. I will look for it again. If I find it I will post it.
Are you using standalone VB, or VBA (which is a subset of true VB, and is available from within an Office app like Access or Excel) ?
If you're using VB, ref the code in this thread at a sister-site. Note that CutePDF doesn't allow you to programatically supply the pdf file name - you have to enter it manually each time you print.
Last edited by loquin; 08-31-06 at 19:03.
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert
A year ago I found CutePDF via this site, which was very usefull as I no longer had use of Adoby Writer, which had been used to automate printing PDF Reports from Excel.
This was achieved using SendKeys. Not recomended I know but needs must !
However, using CutePDF was not strait forward (is it ever!).
Having selected the PDF printer in code, and constucted the file (with path) name(s), this code was used with Adobe Writer
Sub PrintToAdobePDF(FilePath As String)
SendKeys "%FP~" & FilePath & "~", True
After experimenting with CutePDF I found that a delay was required, therefore this code used with CutePDF
Sub PrintToCutePDF(FilePath As String, RequiredDelay As Single)
SendKeys "%FP~", True
SendKeys FilePath & "~", True
A delay of 2.5 seconds seemed to work.
The Pause() function also seemed to need DoEvents in the loop.
I have not used this a great deal as the requiement for the reports was lost at this time, and I suspect it is not very robust, but it was the only way I could do it??
The previous Adobe writer worked very well creating dozens of reports over an uninterupted 20 minute period. But you do have to stop all other programs interfering while it runs (ie. tun off e-mail 'you got mail' popups as these then take the sent keys !) .
I don't know if that helps, but I would be interested if it works for you.