How to automatically run and email crystal reports

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.

How?

  1. Download Crystal Reports Exporter from here http://www.rainforestnet.com/crystal-reports-exporter/download.htm
  2. Download Blat from here http://sourceforge.net/projects/blat/files/Blat%20Full%20Version/
  3. Export the downloaded ZIP files and save the programs to a new folder, in this example called ‘crystal’
  4. Create a new cmd file (text file), in this example called ‘run.cmd’
  5. Add the following contents, and edit as per your requirements:
    1. The to email address
    2. The from email address
    3. the mail server
  6. @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 to@address.com -subject "Monthly report for: %%~nf" -attach "%~dp0\%%~nf.pdf" -server MAILSERVER.LOCAL -f from@adress.com)
  7. Copy one (or more) of your Crystal Reports to the ‘crystal’ folder. Note: the report must have a rpt extension.
  8. Run ‘run.cmd’ it will run and email each of your Crystal Reports
  9. CrystalReport-AutomaticScheduleReport1
  10. 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?

  1. First, the cmd script looks for any PDF files in the folder and deletes them.
  2. it then looks for any Crystal Report rpt files in the contained folder
  3. then, for each rpt file it finds it runs crexport, saving the report as a PDF in the contained folder
  4. 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.