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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Olecontrol parameters

Status
Not open for further replies.

cfriedberg2

Programmer
Aug 13, 2005
34
US
I have placed an olecontrol on a form in VFP 6.0. The name of the control is CRViewer9.CRViewer.9.2. It will display a Crystal Report very nicely. That information can be found in thread faq184-3039.

I want to call the form with the viewer with the following command from a menu.
do form frmrptvur.scx with curdir() + "\Crystal Reports\Gross Profit by Materials Detail ld.rpt"

The problem is that the parameter, the report name, does not seem to be passed. I do not know how to get the parameter into the control.

I would appreciate any help.

Thanks.
 
In general, it is the form's Init event that receives the parameter. You need to put an LPARAMETERS statement at the start of the Init.

But, because the parameter will go out of scope when the Init finishes, you also need to store it in a property of the form. You can then refer to that property when launching your CR viewer.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
The init event of the form does not execute before the init event of the control. I had tried to assign the value to the tag property of the form, but it is too late for the olecontrol to use it.

That is the reason that passing the parameters is so difficult.
 
You could always pass the parameter in your 'main.prg'. Then within the main, have a public variable to accept the parameter. Your olecontrol could then use the public variable:

*... main.prg
PARAMETERS cFileName

PUBLIC pcFileName
STORE cFileName TO pcFileName

DO FORM whatever



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
I finally got it to work. Thank you for all your comments; they were a big help.

1. The call from the menu is:
do form frmrptvur with curdir() + "\Crystal Reports\Gross Profit by Materials Detail ld.rpt"

2. The init event of the form is:

LPARAMETERS cReportName, nClientId
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 = "SomeReport"
*** 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 Thisform.olecontrol1
.Top = 5
.Left = 5
.Height = ThisForm.Height - 2
.Width = ThisForm.Width - 2
ENDWITH

3. The init event of the olecontrol is:

*** 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

4. This is the code in the resize event of the control.

This.olecontrol1.EnableExportButton = .T.
This.olecontrol1.EnableGroupTree = .T.
This.olecontrol1.EnableRefreshButton = .T.
This.olecontrol1.Zoom(1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top