Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem viewing Crystal report in VFP 9 SP2 1

Status
Not open for further replies.

MikeMV

MIS
May 15, 2006
131
US
Hello,

I am trying to learn to view and print Crystal reports from within VFP 9 SP2 and I am not getting results, I wonder if what I am trying to do will even work.

I have Crystal Reports 2008 installed in my computer, is VFP able to view reports saved with this version?

In IntelliSense I selected Crystal ActiveX Report Viewer Library 11.5, there are other 2 versions 10.2 and 10.5, I tried both of these, but still no luck.

The code I am using to test viewing the report is:

LOCAL oCR AS CRAXDRT.Application
LOCAL oRpt AS CRAXDRT.Report
oCR = CREATEOBJECT("CrystalRuntime.Application")
oRpt = oCR.OpenReport("C:\Temp\Inventory.rpt")

When I run it I get no errors, but nothing happens, the program terminates pretty quickly. I wonder if there is a way to trap any activity that may be going on in the background?

I will greatly appreciate any feedback, I may be trying to do this with the wrong tools.

Mike.
 
Mike,

You're missing a few steps.

First, you need to drop the Report Viewer control onto a form.

Once you've done that, you need to open the report (which you are doing), and then associate the report with the control (which you are not), and finally view the report.

You should put code similar to the following in the Init of the viewer control:

Code:
oCR = CREATEOBJECT("CrystalRuntime.Application")
oRpt = oCR.OpenReport("C:\Temp\Inventory.rpt")
THIS.ReportSorce = oRpt
THIS.ViewReport

That works for me. Give it a try and let us know what happens.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks Mike

Interesting how simple it was to get it to work. I noticed that in the above example I don't even need the code outside of the form, I commented it out and it still runs. Does that make sense?

Now I am going to work on having it print automatically, I'll reach out if I get stuck.

Thanks again.
 
Mike,

Yes, it makes perfect sense. I'm glad you've got it working.

There are lots of ways of customising the viewer control. You'll have fun exploring the properties and methods.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks Mike,

Do you know of any good source of documentation for the controls, properties, methods, etc?

Would this information come from Crystal/Business Objects?
 
Mike,

There is a help file that comes with CR that lists all the PEMs. The name and location of the file varies with the version. In CR XI, it's:
..\Crystal Reports 11\Developer Files\Help\En\CrsytalDevHelp.chm

The information in the file is not great, but it will give you a good start - if you supplement it with a helping of trial-and-error.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike,

I have the small app running great, the only thing I can't seem to figure out is how to print silently without the program stopping to ask for the printer. I have played around with oRpt.PrinterSetup() and oRpt.SelectPrinter() and nothing seems to click. Is there a way to do this? I would like to have the users click on a shortcut and get the report without any interaction.

I am running VFP 9.0 SP2 and the report was created with CR 2008, in Intellisense I added Crystal ActiveX Report Viewer Library 11.5

I'll greatly appreciate any help you can provide.

 
Hello Mike.

The different versions of crystal are not equal. For the version 10, 11 and 11.5 (11 Rel 2) you need the developer edition (if I remember) to view and distribute runtimes to run with VFP. Crystal 2008 is, in fact, Crystal 12 and Business object (now SAP) say that they discontinued the RDC (Report Designer Component), to fit better with Visual Studio. That’s it for the history.

To print report, as Mike said, you have to create a Crystal object. Again, the version you use is important;

For v. 10

Code:
oCrystalReport = Createobject("CrystalRuntime.Application.10")


For v.11 or 11.5

Code:
oCrystalReport = Createobject("CrystalRuntime.Application.11")

You have to open the report

Code:
lcReport = “C:\TEST\prtCust01.RPT”
oCrystalRp = loCrystalReport.OpenReport(lcReport)


To print to a printer, first, you have to find the printer name, port and driver. For a reason I don’t know, Crystal reset the orientation, after you set the printer drivers, you have to set the orientation and paper size


Code:
lnPaperOrientation = oCrystalRp.PaperOrientation
lnPaperSize = oCrystalRp.PaperSize

lcPrtDrv = “Canon iP1800 series”
lcPrtName = “Canon iP1800 series”
lcPrtPort = “USB2”

oCrystalRp.SelectPrinter(lcPrtDrv, lcPrtName, lcPrtPort)

oCrystalRp.PaperOrientation = lnPaperOrientation
oCrystalRp.PaperSize = lnPaperSize

To print

Code:
oCrystal.oCrystalRp.Printout(.F.)

Hope it help.

Bye

Nro


 
Thanks for the information Nro.

I have the small app running using a form and it prints ok, the only thing is that it stops for me to select the printer from the list of installed printers in the computer. I am trying to see if I can get it to print to the default printer without user intervention, this will run on 2-3 computers that may not have the the same printer installed.

Do you know of a way to accomplish this?

Thanks again.
 
Hello Mike

First, you have to find witch printer port, printer name and driver for each printer they use. If it’s a network printer, it’s very simple. If it’s local printers, you have to look for each location.

Code:
DECLARE INTEGER GetDefaultPrinter ;
	IN winspool.drv ;
    STRING  @pszBuffer,;
    INTEGER @pcchBuffer

*** Find default printer configured on the PC ***
lnBufsize = 250
lcPrinter = REPLICATE(CHR(0), lnBufsize)
=GetDefaultPrinter(@lcPrinter, @lnBufsize)
lcPrinter = SUBSTR(lcPrinter, 1, AT(Chr(0),lcPrinter)-1)

*** Find Printer name, port and driver ***
=APRINTERS(laPrn,1)
lnDefault = ASCAN(laPrn, lcPrinter,1,ALEN(laPrn,1),1,1+8)

lcPrinterName = laPrn[lnDefault,1]
lcPrinterPort = laPrn[lnDefault,2]
lcPrinterDrv = laPrn[lnDefault,3]

Then, you have to set the printer to the report

Code:
*** Print ***
loCrystalReport = Createobject("CrystalRuntime.Application.11")

lcReport = "C:\Objitech\Apps\LesfabPO\Crystal\V11\rptPrice01.rpt"
loCrystalRp = loCrystalReport.OpenReport(lcReport)

loCrystalRp.SelectPrinter(lcPrinterDrv, lcPrinterName, lcPrinterPort)
loCrystalRp.Printout(.F.)

If the program still asks for a printer, maybe it’s because of the version or the context of the RDC you use. Just give us the code you use.

Bye

Nro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top