Crystal Reports

schlosser0169

New Member
I am using Crystal Reports 8.5. I am trying to pass a parameter from my progress app to Crystal Reports. My parameter is not
being passing to the SQL query.
How do I "link up" my parameter to the SQL query.

I have used some code I found on this site but I am missing
something.

DEF VAR sReportName AS CHARACTER.
DEF VAR sName AS CHARACTER.
DEFINE VARIABLE sUserId AS CHARACTER NO-UNDO.
DEFINE VARIABLE sPassword AS CHARACTER NO-UNDO.
def var hCRApp as com-handle no-undo.
def var hCRRpt as com-handle no-undo.

sReportName = "c:\export\report1.rpt".
sName = "sports".
sUserId = "user".
sPassword = "password".

/* create handle to CRAXDRT */
CREATE "CrystalRuntime.Application" hCRApp NO-ERROR.

/* open the report via RDC Com object */
hCRRpt = hCRApp:OpenReport(sReportName, 1).

/* Send LogOnInfo to connect to database */
hCRRpt:Database:Tables(1):SetLogOnInfo(sName, "", sUserId, sPassword).

/* Replace Crystal Parameter */
hCRRpt:parameterFields(1):SetCurrentValue(custNum).

CustNum is my input variable.


Thanks

Sandra Schlosser
 

phirst

New Member
Hi Sandra,

Try this:

DEFINE VARIABLE hCRParams AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hCRParFld AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE iCRCnt AS INTEGER NO-UNDO.

...

/* don't prompt user for parameters */
hCRRpt:EnableParameterPrompting = FALSE.

/* parameters */
hCRParams = hCRRpt:parameterFields.

/* empty parameters */
/* helps if all your reports don't have the same number of parameters */
DO iCRCnt = 1 TO hCRParams:Count:
hCRParFld = hCRParams:Item(iCRCnt).
NO-RETURN-VALUE hCRParFld:ClearCurrentValueAndRange().
END.

/* set the parameter number 1 */
/* the order the parameters are defined in CR */
hCRParFld = hCRParams:Item(1).
NO-RETURN-VALUE hCRParFld:AddCurrentValue(custNum).

Check out C:\Program Files\Seagate Software\Crystal Reports\Developer Files\Help\Developr.hlp. I found all that I needed in there.

Cheers.
 
Top