Output Direct to PDF from VBA (1 Viewer)

SteveClarkson

Registered User.
Local time
Today, 08:32
Joined
Feb 1, 2003
Messages
435
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

Registered User.
Local time
Today, 08:32
Joined
Mar 30, 2002
Messages
257
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

Registered User.
Local time
Today, 08:32
Joined
Feb 1, 2003
Messages
435
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:
Code:
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.
 

rachelcrombie

New member
Local time
Today, 03:32
Joined
Nov 29, 2011
Messages
1
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:
Code:
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.

Hello!

I am apparently trying to do the same thing that you all were (I have some reports in Crystal that I want to open and create pdf's of using VBA in MS Access). However, I am struggling to get the code to work. I am using MS Access 2000. I am curious as to the datatypes of 'rep' and 'appl'. I guessed them as Object and Report, respectively. However, the code still does not work for me whenever I define them as such. Also, is 'ExportOptions' and 'Export' keywords in MS Access or are these also user defined variables? Attached is the code that I have adapted that is not working. Any pointers would be greatly appreciated! Again, all I am trying to do is open a Crystal report in MS Access, and create a pdf of it, and then place it in a file on our network drive. I just want to automate this process using VBA. Thanks!


Function crystalLink4()
DoCmd.SetWarnings False
Dim rep As Object
Dim appl As Report
Set rep = appl.OpenReport("G:\Public\Sharepoint\Service Related\Meter Asset\Water Consumption Review\Additions--PREM NOTE--Water Meters to Review.rpt", 1)
ExportOptions.DiskFileName = "G:\Public\Sharepoint\Service Related\Meter Asset\testCons\" & Format(Now(), "yyyy") & " - " & Format(Now(), "mmm") & " - " & "GAS" & ".pdf"
ExportOptions.DestinationType = crEDTDiskFile
ExportOptions.FormatType = crEFTPortableDocFormat
Export False
End Function
 

johnnyoc

New member
Local time
Today, 00:32
Joined
Apr 30, 2016
Messages
1
Hello!

I am apparently trying to do the same thing that you all were (I have some reports in Crystal that I want to open and create pdf's of using VBA in MS Access). However, I am struggling to get the code to work. I am using MS Access 2000. I am curious as to the datatypes of 'rep' and 'appl'. I guessed them as Object and Report, respectively. However, the code still does not work for me whenever I define them as such. Also, is 'ExportOptions' and 'Export' keywords in MS Access or are these also user defined variables? Attached is the code that I have adapted that is not working. Any pointers would be greatly appreciated! Again, all I am trying to do is open a Crystal report in MS Access, and create a pdf of it, and then place it in a file on our network drive. I just want to automate this process using VBA. Thanks!

Function crystalLink4()
DoCmd.SetWarnings False
Dim rep As Object
Dim appl As Report
Set rep = appl.OpenReport("G:\Public\Sharepoint\Service Related\Meter Asset\Water Consumption Review\Additions--PREM NOTE--Water Meters to Review.rpt", 1)
ExportOptions.DiskFileName = "G:\Public\Sharepoint\Service Related\Meter Asset\testCons\" & Format(Now(), "yyyy") & " - " & Format(Now(), "mmm") & " - " & "GAS" & ".pdf"
ExportOptions.DestinationType = crEDTDiskFile
ExportOptions.FormatType = crEFTPortableDocFormat
Export False
End Function

I know this is an old post, but I thought I'd post the working code in case anyone else needs it :)

Note: Make sure to include the following VBA Reference under Tools->References...
Crystal Reports ActiveX Designer Run Time Library 11.5
(or simular)

Function crystalLink4()
Dim appl As CRAXDRT.Application
Dim rep As CRAXDRT.Report

DoCmd.SetWarnings False

Set appl = New CRAXDRT.Application
Set rep = appl.OpenReport("G:\Public\Sharepoint\Service Related\Meter Asset\Water Consumption Review\Additions--PREM NOTE--Water Meters to Review.rpt", 1)

With rep
.ExportOptions.DiskFileName = "G:\Public\Sharepoint\Service Related\Meter Asset\testCons\" & Format(Now(), "yyyy") & " - " & Format(Now(), "mmm") & " - " & "GAS" & ".pdf"
.ExportOptions.DestinationType = crEDTDiskFile
.ExportOptions.FormatType = crEFTPortableDocFormat
.Export False
End With

DoCmd.SetWarnings True
End Function
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom