Exporting Crystal Report to PDF upon Form loading in VB

Posted on 2003-12-03
Last Modified: 2008-02-26
I am trying to get a Crystal report to automatically export to a PDF file at a specific name and location. I want this to occur on the form load event (or form activate event) in a VB6 project. I beleive I have almost all the parts needed to do this but I still am having some dificulty.

I want the Report called "crptLocalTest.dsr" which is already in the project as a crystal report.
           (or I can also run a "LocalTest.rpt" that can be in the local app directory)
I want it to export in PDF format to the directory called C:\Temp\
I want it named Output.pdf
It will also need to overwrite the "Output.pdf that will be currently in the directory.

I want this all to occur withiut any prompting past starting the VB app. It seems like I need to modify some of the code below that I have been working with.....

    crptLocalTest.ExportOptions.DiskFileName = ("C:\Temp\Output.PDF")
    crptLocalTest.Action = 1
    crptLocalTest.ExportOptions.FormatType = crEFTPortableDocFormat

Can anybody help me make my way through this, I am pretty new to VB so try to keep it as simple as possible.
Question by:DavidNPD
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 101

Expert Comment

ID: 9868931

Expert Comment

ID: 9868956
There isn't much to it.  Assuming that your report doesn't require any user interaction such as logging on to the database, or supplying parameter values, simply set up the values you want in the .ExportOptions object first, then call the .Export() method.

You may wish to include ".ExportOptions.PDFExportAllPages = true" in order to ensure that all pages are included, but that's about it in addition to what you quoted above.  The only other thing I would mention is that should you wish to suppress Crystal's export options prompts, don't forget to supply the "false" argument to Report.Export().

Hopefully this will get you going...  if not, post a comment any specific problems your are encountering, and someone will get you on your way.


Author Comment

ID: 9869237
I have been working with that sample app. That his how I got as far as I did. I am using 8.5 deveolopers edition.

deguy, one specific problem that I am having is that when I use

crptLocalTest.Export (false) to surpress the confirmations I get an error: "Runtime error '-2147190548" telling me that the export DLL are not installed. They are and they work when I get the prompts but when I try to use "False" I get the error.

Can you see any mistakes in the code sample I have supplied, because that just brings up the dialog box for confirmations.
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT


Expert Comment

ID: 9869360
>Can you see any mistakes in the code sample I have supplied, because that just brings up the
>dialog box for confirmations.

From the code you posted it looks as though you're calling the .Export() method before you set up the .ExportOptions object.  Is that correct?

Author Comment

ID: 9874771
The exact code, that is located in the Form_load area is this:

        crptLocalTest.ExportOptions.PDFExportAllPages = True
        crptLocalTest.ExportOptions.FormatType = crEFTPortableDocFormat
        crptLocalTest.ExportOptions.DiskFileName = (App.Path & "\Output.PDF")
        crptLocalTest.Export (False)

When I do it this way  (with the promt to false) I get an error that says:

Run-Time error '-2147190548 (800478ec)':
Missing or out-of-date export DLL.

But in fact I do have the export dls installed, as if I do not ask for the prompt to be supressed I can actually export the report correctly, though it asks me for the pages, location and file name.


Accepted Solution

deguy earned 100 total points
ID: 9874855
Oops...  I missed a vital part yesterday.  Are you setting the .DestinationType property of .ExportOptions?  It should be crEDTDiskFile for exports to disk.


Author Comment

ID: 9874886
THAT did it !
Here is the code that is now working, Thanks

        crptLocalTest.ExportOptions.PDFExportAllPages = True
        crptLocalTest.ExportOptions.FormatType = crEFTPortableDocFormat
        crptLocalTest.ExportOptions.DiskFileName = (App.Path & "\Output.PDF")
        crptLocalTest.ExportOptions.DestinationType = crEDTDiskFile
        crptLocalTest.Export (False)

Expert Comment

ID: 9874940
Glad I could help!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question