The following is a strategy for integrating Crystal Reports 8.5 (using the Report Designer Component (RDC)) with FoxPro 7.0. The concept is to create a ôReport Viewingö form that is called from a menu or a button on another form. I use one æReport ViewerÆ form and pass the report name and other parameters from the preceding form. I will cover topics like the following: preview the report, pass parameters to the report, and manipulating the viewer when it initiates on the form.
This following code is a combination of Craig BernstonÆs and the Crystal Reports Documentation.
ò Create a form ò Add the Crystal Viewer OLE control to the form ò Place the following code in their mentioned methods
IF nError != 1440 * Error 1440 is caused by the Crystal Report Viewer * when you try to display it before the report is done * loading. We'll ignore it and trap all other errors. DODEFAULT() ENDIF ENDPROC
PROCEDURE Init PARAMETERS cReportName, nClientId
*** Assign the ReportName This.Reportname = cReportName
LOCAL crapplication, crreport
*** Create the Report using RDC crapplication = CREATEOBJECT("CrystalRuntime.Application") crreport = ("CrystalRuntime.Report") crreport = crapplication.OpenReport(cReportName) ThisForm.olecontrol1.ReportSource = crreport
IF cReportName = "Reports\MASTER-REPORT.rpt" *** Assign the ClientId This.currentclient = nClientId *** Pass Parameters crreport.parameterfields.item(1).SetCurrentValue (nClientId) ENDIF
*** Preview the Report ThisForm.oleControl1.ViewReport
*** Sets the Properties of the Report Viewer WITH This.olecontrol1 .Top = 5 .Left = 5 .Height = ThisForm.Height - 2 .Width = ThisForm.Width - 2 ENDWITH