If you’ve been looking for a way to automatically schedule and email Crystal Reports then there’s a free solution – a combination of crexport, blat, and the Windows Task Scheduler.
crexport – Crystal Reports Exporter is a free Windows Command Line tool which allows you to run reports without Crystal Reports installed. It allows you to export the report as a file or straight to a printer.
blat – Blat is a free Windows Command Line tool that allows you to send emails, with attachments using your existing SMTP (mail) servers.
- Download Crystal Reports Exporter from here http://www.rainforestnet.com/crystal-reports-exporter/download.htm
- Download Blat from here http://sourceforge.net/projects/blat/files/Blat%20Full%20Version/
- Export the downloaded ZIP files and save the programs to a new folder, in this example called ‘crystal’
- Create a new cmd file (text file), in this example called ‘run.cmd’
- Add the following contents, and edit as per your requirements:
- The to email address
- The from email address
- the mail server
@echo off ECHO Deleting existing PDF documents del *.pdf for %%f in (%~dp0*.rpt) do ( ECHO Creating PDF report for %%~nf "%~dp0crexport.exe" -F "%~dp0%%~nxf" -O "%~dp0\%%~nf.pdf" -E pdf ECHO Emailing PDF report for %%~nf "%~dp0blat.exe" -body "%%~nf" -to [email protected] -subject "Monthly report for: %%~nf" -attach "%~dp0\%%~nf.pdf" -server MAILSERVER.LOCAL -f [email protected])
- Copy one (or more) of your Crystal Reports to the ‘crystal’ folder. Note: the report must have a rpt extension.
- Run ‘run.cmd’ it will run and email each of your Crystal Reports
- Once you’ve confirmed the reports are correct and the emailing is working you can use the Windows Task Scheduler to automate the process.
What does the script do?
- First, the cmd script looks for any PDF files in the folder and deletes them.
- it then looks for any Crystal Report rpt files in the contained folder
- then, for each rpt file it finds it runs crexport, saving the report as a PDF in the contained folder
- It then emails the exported report, individually to the specified address.
Help! It’s not running a report
Does the report contain prompts? If so, either remove the prompts, hard code the answers to the prompts to read the documentation for crexporter for how to handle crystal reports prompts.
If you get an error message which reads ‘System Error: Could not load file or assembly’ make sure you’ve installed the Microsoft .NET Framework 4 and SAP Crystal Reports runtime engine for .NET Framework 4. 32-bit version or 64-bit version.
If it still doesn’t work, try checking that the report runs using normal Crystal Reports.
Also – I’ve found that using the ‘user’ DSN in the ODBC works when the ‘system’ doesn’t.