View Full Version : Output Direct to PDF from VBA


SteveClarkson
09-21-2006, 01:55 AM
Hello

I have recently learnt how to use Crystal Reports - and had a basic example built into an access database for me, to show me how to run a crystal report from within access, using the crystal activex control.

I would like to (from VBA) export a whole bunch of crystal reports to PDF, and save them to a network drive.

Using the activex and a bit of VBA, I can open the crystal viewer preview window, or send direct to printer - but I can't for the life of me figure out how to send direct to PDF.

There are lots of options in the "Print to File" option of the activex, but none of them are PDF, they are all XLS, CSV, DIF etc.


Can anyone help???

Thanks!

edtab
09-21-2006, 02:55 AM
No sure if I'm missing something here. You mentioned that you can
send your report directly to a printer. At work, we convert Access reports
to PDF by "printing" them to a PDF writer (defined as a printer). Could you not do the same with Crystal reports?

SteveClarkson
09-21-2006, 03:28 AM
I don't think it would provide the necessary level of automation - I just want to be able to hit a button, and have all the 11 reports outputted to PDF and saved on the network, using a filename and date.

As it happens, in the last few minutes, I have found a solution that seems to work really well.

The code is:
Sub ExportToPDF(ReportFile As String)
Set rep = appl.OpenReport("G:\Ops\Stock Reconciliations\Reports\" & ReportFile & ".rpt", 1)
rep.ExportOptions.DiskFileName = "G:\Ops\Stock Reconciliations\Archive\" & Format(Now(), "yyyy") & " - " & Format(Now(), "mmm") & " - " & ReportFile & ".pdf"
rep.ExportOptions.DestinationType = crEDTDiskFile
rep.ExportOptions.FormatType = crEFTPortableDocFormat
rep.Export False
End Sub

I adapted that from some code I FINALLY found on the net, from Google Groups (what a great idea that is!).
All I have done is bunged it into a module, so I can call it from all over the place, and only have to specify the filename, but that could all be changed quite easily.

Thanks for your help, none-the-less.

Humpty
09-25-2006, 07:13 AM
Also worth having a look at this Steve:

http://www.lebans.com/reporttopdf.htm