Solved

Crystal Reports 8.5 VCL - Printing Multiple Reports

Posted on 2004-04-10
6
1,478 Views
Last Modified: 2007-12-19
I am having trouble printing a report with the TCrpe VCL object.

I am using Borland C++ Builder 5, Crystal Reports 8.5, and crpe32.dll is version 8.5.0.217.

I set the Output property of the TCrpe object to toPrinter and call Execute( ).  This prints fine the first time, but if I try to print a second time nothing happens.  I get no errors and every status property I can find indicates that the report printed sucessfully.  The only way I can get the program to print again is to restart the program.  I can always print only once.  However, if I set Output=toWindow, I can print normally from the preview screen.

Every time the report unsuccessfully tries to print, the report appears in the Printer's Job Queue for an instant and then after no more than a couple seconds disappears without printing.  This same behavior occurs on all Windows operating systems and printers that I have tried.  It also doesn't matter if it is a local or network printer.

Is this a bug in the print engine that has been fixed with an updated version of crpe32.dll?
Is something in the TCrpe object somehow destroying the print job before it is printed?

Here is the code:

    ReportCrpe->Clear( );
    ReportCrpe->ReportName = reportFilename;  
    ReportCrpe->Output = toPrinter;
    ReportCrpe->Printer->Name = printerName;
    ReportCrpe->PrintOptions->Copies = 1;
    ReportCrpe->PrintOptions->Collation = Collated;
    ReportCrpe->Execute( );


Please Help!
0
Comment
Question by:AdrianSRU
  • 3
  • 2
6 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 10802997
How is this code called to do multiple reports?

Is a new ReportCrpe object created for each report?

I suspect you need to create a new ReportCrpe and destroy it when the printing is complete.

I know i have trouble from VB if I don't "destroy" the object when I am done with it.

I think the problem with the 2nd and later reports is the database connections aren't changed and the report therefore has no data or errors out because the tables aren't correct.  I suspect the CLEAR method isn't doing the full job.

If you print the same report twice does the second one print?

mlmcc
0
 
LVL 12

Author Comment

by:AdrianSRU
ID: 10806447
mlmcc:  Thanks for responding to my question.  I appreciate it!

First off, I have to revise my original question slightly.  I was mistaken when I said, "It also doesn't matter if it is a local or network printer."  Printing the reports works just fine on a local printer but fails on network printers.  I apologize for the mistake.

To answer your questions:

"How is this code called to do multiple reports?"
I have a list of reports displayed on a form.  The user selects a report and clicks either a View button (Output=toWindow, brings up the preview window) or a Print button (Output=toPrinter, prints report without preview).  The first time the Print button is clicked, the report prints as it should.  If the print button is clicked again the report does not print.  After the first report is printed, if the View button is clicked, the preview window appears and the report can be printed from there, but that extra step is annoying and time consuming.

"Is a new ReportCrpe object created for each report?"
I have tried creating a separate instance of the TCrpe object for each report and destroying it after the Execute method is called.  The result is the same.

"If you print the same report twice does the second one print?"
I tried modifying the code to call the Execute method twice for the same report:

    ReportCrpe->Clear( );
    ReportCrpe->ReportName = reportFilename;  
    ReportCrpe->Output = toPrinter;
    ReportCrpe->Printer->Name = printerName;
    ReportCrpe->PrintOptions->Copies = 1;
    ReportCrpe->PrintOptions->Collation = Collated;
    ReportCrpe->Execute( );
    ReportCrpe->Execute( );

The report only prints once and I have to restart the program before I can print again.


AdrianSRU
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 125 total points
ID: 10813274
>>Printing the reports works just fine on a local printer but fails on network printers.
Are you saying you can print multiple times or multiple reports to a local printer or that local printing works for the first one and network printing doesn't work at all?  Do the users have the printer requested installed?

Crystal will use the default printer and unless you change that through code it generally doesn't change.


This almost sounds like a timing issue.  What happens if you print a report, wait for it to print, then print another report?

mlmcc
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 3

Expert Comment

by:DarrenZai
ID: 10821094
Not very familiar with the VCL these days, but the code that I have here calls the CloseJob Method after execution.

crpe.execute
if crpe.PrintEnded then
   crpe.CloseJob
endif
0
 
LVL 12

Author Comment

by:AdrianSRU
ID: 10823107
I have been able to get my code to work but the solution puzzles me a little.

I was able to print multiple reports on a local printer but only one report on a network printer.

mlmcc, you said: "Crystal will use the default printer and unless you change that through code it generally doesn't change."
I tried setting the default printer to be a network printer, and then I didn't set the name of the printer in code.  I was then able to print multiple reports on the network printer.

Borland C++ Builder provides a TPrinter object that can be used to obtain a list of installed printers.  I was using that to let the user select where to print the report.  The TPrinter object was giving me the names of network printers in the format:
\\<computer name>\<printer name>
If I convert that to:
<printer name> on <computer name>
all of a sudden I can print multiple reports on a network printer!

It would make a lot more sense to me if the "\\<computer name>\<printer name>" format did not print at all, but it prints once.  I'd like to know why it works that way, but since my stuff is working properly now, it's a curiousity instead of an urgent problem.

Thanks for the help!
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 10829077
Glad I could help

mlmcc
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now