Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Crystal Reports 8.5 VCL - Printing Multiple Reports

Posted on 2004-04-10
6
Medium Priority
?
1,503 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
[X]
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
  • 3
  • 2
6 Comments
 
LVL 101

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 101

Accepted Solution

by:
mlmcc earned 375 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
Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 
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 101

Expert Comment

by:mlmcc
ID: 10829077
Glad I could help

mlmcc
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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