Go Back   Access World Forums > Apps and Windows > Crystal Reports

 
Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
Old 09-21-2006, 01:55 AM   #1
SteveClarkson
Newly Registered User
 
Join Date: Feb 2003
Location: Kent, SE UK
Posts: 435
Thanks: 0
Thanked 2 Times in 2 Posts
SteveClarkson is on a distinguished road
Output Direct to PDF from VBA

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!

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Steve
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
SteveClarkson is offline   Reply With Quote
The Following User Says Thank You to SteveClarkson For This Useful Post:
hassanogaibi (06-27-2016)
Old 09-21-2006, 02:55 AM   #2
edtab
Newly Registered User
 
Join Date: Mar 2002
Location: Toronto, Ontario, Canada
Posts: 257
Thanks: 0
Thanked 3 Times in 3 Posts
edtab
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?
edtab is offline   Reply With Quote
The Following User Says Thank You to edtab For This Useful Post:
hassanogaibi (06-27-2016)
Old 09-21-2006, 03:28 AM   #3
SteveClarkson
Newly Registered User
 
Join Date: Feb 2003
Location: Kent, SE UK
Posts: 435
Thanks: 0
Thanked 2 Times in 2 Posts
SteveClarkson is on a distinguished road
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.

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Steve
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
SteveClarkson is offline   Reply With Quote
The Following User Says Thank You to SteveClarkson For This Useful Post:
hassanogaibi (06-27-2016)
Old 09-25-2006, 07:13 AM   #4
Humpty
Registered User
 
Join Date: May 2004
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Humpty is on a distinguished road
Also worth having a look at this Steve:

http://www.lebans.com/reporttopdf.htm
Humpty is offline   Reply With Quote
The Following User Says Thank You to Humpty For This Useful Post:
hassanogaibi (06-27-2016)
Old 11-29-2011, 06:53 AM   #5
rachelcrombie
Newly Registered User
 
Join Date: Nov 2011
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
rachelcrombie is on a distinguished road
Re: Output Direct to PDF from VBA

Quote:
Originally Posted by SteveClarkson View Post
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
rachelcrombie is offline   Reply With Quote
The Following User Says Thank You to rachelcrombie For This Useful Post:
hassanogaibi (06-27-2016)
Old 04-29-2016, 04:22 PM   #6
johnnyoc
Newly Registered User
 
Join Date: Apr 2016
Location: California, USA
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
johnnyoc is on a distinguished road
Re: Output Direct to PDF from VBA

Quote:
Originally Posted by rachelcrombie View Post
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

johnnyoc is offline   Reply With Quote
The Following User Says Thank You to johnnyoc For This Useful Post:
hassanogaibi (06-28-2016)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PDF and VBA Code Help bonekrusher Modules & VBA 1 01-25-2006 08:40 AM
Converting PDF to TXT with VBA or VB daceyj Modules & VBA 0 01-19-2006 08:12 AM
VBA - output dynamic $ query to excel - $ gets truncated PhilipEwen Modules & VBA 3 11-17-2003 02:04 PM
VBA to automate pdf process (from html) yippie_ky_yay Modules & VBA 5 05-12-2003 11:16 AM
Output Report as Pdf file and E-mail mous Reports 0 03-11-2003 09:24 AM




All times are GMT -8. The time now is 10:03 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World