Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Running crystal reports from within foxpro
Message
General information
Forum:
Visual FoxPro
Category:
Third party products
Miscellaneous
Thread ID:
00388015
Message ID:
00390259
Views:
19
I have been using Crystal Reports 7 with VFP6. I have a setup screen written in VFP that allows the user to select the report and to set up some of the parameters. They can also select margins for the report and the sort order.

Here is some sample code:

PUBLIC goCR, goReport, goParameters, goSortFields, goPrintWindowOptions, ;
goPageSetup, goView

* Open the Crystal Reports Application
goCR = CREATEOBJECT("Crystal.CRPE.Application")

* Report an error if the Crystal Reports engine cannot be opened
IF TYPE("goCR") # "O"
MESSAGEBOX("Could not open Crystal Reports engine.", ;
1 + 48, ;
"Error: Report engine not available.")
RETURN .F.
ENDIF

* Select the report to be displayed
lcReport = THISFORM.txtcReport.Value + ".rpt"
goReport = goCR.OpenReport(lcReport)

* Report an error if the report cannot be opened
IF TYPE("goReport") # "O"
MESSAGEBOX("Could not open the report " ;
+ lcReport, ;
1 + 48, ;
"Error: Report not available.")
RETURN .F.
ENDIF

* Tell the report to not prompt for parameters
goReport.ParameterPromptingEnabled = .F.

* Now set the parameter values
goParameters = goReport.ParameterFields

* Set the date to be printed on the report
goParameters.ITEM(1).SetCurrentValue(ldReportDate)

* Set the value of the report title
goParameters.ITEM(2).SetCurrentValue(lcRptTitle)

* Change the sort direction based on the order chosen by the user
goSortFields = goReport.RecordSortFields

IF lcSort = "New to Old"
goSortFields.ITEM(1).SortDirection = 0
ELSE
goSortFields.ITEM(1).SortDirection = 1
ENDIF

goPrintWindowOptions = goReport.PrintWindowOptions

* Display the printer setup button on the report preview screen
goPrintWindowOptions.HasPrintSetupButton = 1

* Set the default paper orientation to landscape
goPageSetup = goReport.PageSetup
goPageSetup.PaperOrientation = 2

* Set the page margins
goPageSetup.TopMargin = (THISFORM.txtnTMargin.VALUE * 1440)
goPageSetup.BottomMargin = (THISFORM.txtnBMargin.VALUE * 1440)

* Set the preview window to be the same height and width as the screen
lnWidth = _SCREEN.WIDTH
lnHeight = _SCREEN.HEIGHT
lcReportName = "Name of Report"

goView = goReport.PREVIEW(lcReportName,0,0,lnWidth,lnHeight)
goView.ShowFirstPage()

Hope this helps.
Pauline
Previous
Reply
Map
View

Click here to load this message in the networking platform