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

Unlinked main and sub-report parameter passing...

Status
Not open for further replies.

redlynne

Programmer
May 29, 2003
15
PH
Hello CR people. I'm new at CR so I'm quite confused on how to pass parameters to a report with an unlinked subreport(the subreport uses an entirely different stored procedure as of the main report). When I preview my report on the CR design panel..I get the results of both reports when I supply them with parameters needed by both main and sub reports. The problem seems to be passing parameters on the subreport using ASP because when I run my app without the subreport on ASP, it runs great. However, when I try passing parameters of the main and the sub report programmatically, I get an "invalid name error" . I can't seem to pass the subreport parameters and the main report parameters at the same time just like what I'm doing when i preview my whole report on the CR design panel.

Here's my code which runs fine without passing my sub-report parameters.The error seems to come mysteriously from the "select case" portion.

Or, is there an issue when passing main and sub-report parameters all at the same time then executing the report? Can't I just pass them to my .rpt all at the same time since I designed my .rpt (report) to expect all these parameters while pointing the main and the sub report to their own respective stored procedures?


FUNCTION GenerateCrystalReport_8(p_strReportName, p_xmlParams)
DIM objCrystal, objReport, objPageOptions, objExportOptions, objXMLParams
DIM intI, strRPTPath, strTempFilename
DIM strParamName, strParamType, strParamValue

CONST crBooleanField = 9
CONST crDateField = 10
CONST crDateTimeField = 16
CONST crNumberField = 7
CONST crStringField = 12


strTempFilename = GenerateTempFilename()

strRPTPath = "../../CrystalReports/" & p_strReportName & ".rpt"

SET objCrystal = Server.CreateObject("CrystalRuntime.Application")

objCrystal.LogOnServer "P2SSQL.DLL","SQL_Server","PASS","progid","progid"

SET objReport = objCrystal.OpenReport(Server.MapPath(strRPTPath),1)

IF LEN(TRIM(p_xmlParams)) <> 0 THEN

SET objXMLParams = GetXMLDoc(p_xmlParams)

FOR intI = 1 TO objXMLParams.documentElement.ChildNodes.Length

strParamName = objXMLParams.documentElement.ChildNodes(intI - 1).getAttribute(&quot;name&quot;)
strParamType = Lcase(objXMLParams.documentElement.ChildNodes(intI - 1).getAttribute(&quot;type&quot;))
strParamValue = objXMLParams.documentElement.ChildNodes(intI - 1).Text


SELECT CASE strParamType
CASE &quot;number&quot;
CALL objReport.ParameterFields.GetItemByName(strParamName).SetCurrentValue(CInt(strParamValue), crNumberField)

CASE &quot;string&quot;
CALL objReport.ParameterFields.GetItemByName(strParamName).SetCurrentValue(CStr(strParamValue), crStringField)

CASE &quot;boolean&quot;
' do nothing

CASE &quot;date&quot;
CALL objReport.ParameterFields.GetItemByName(strParamName).SetCurrentValue(cDate(strParamValue), crDateTimeField)

CASE &quot;datetime&quot;
'do nothing

END SELECT

NEXT


SET objXMLParams = NOTHING

END IF


Set objExportOptions = objReport.ExportOptions
objExportOptions.DiskFileName = Server.MapPath(&quot;../../CrystalReports/Results&quot;) & &quot;\&quot; & strTempFilename & &quot;.pdf&quot;
objExportOptions.FormatType = 31
objExportOptions.DestinationType = 1


objReport.Export False

ON ERROR RESUME NEXT
IF Err.Number = 0 THEN

GenerateCrystalReport_8 = &quot;<pdffile><![CDATA[&quot; & &quot;../../CrystalReports/Results/&quot; & strTempFilename & &quot;.PDF]]></pdffile>&quot;

ELSE
GenerateCrystalReport_8 = cst_Fail

CALL DisplayError(&quot;IPMS - Crystal Report Error&quot;, intRet, Err.Number & &quot;: &quot; & Err.Description)

Response.End
END IF ... blah..blah..blah...
 
Click [Edit] and [Subreport]. You should find that any field can be linked, including a parameter.

Madawc Williams
East Anglia, Great Britain
 
Thanks Madawc. That's what I did during the design phase of my report. But my purpose is not to link both reports since they call different stored procedures.What I want to do is to place the subreport in the report footer which was sucessful dring my design phase where I just input the parameters when I preview the reports (where CR asks for the parameters of both main and sub reports before displaying the print preview).
My problem is when I pass the parameters programatically using ASP code. I can't seem to pass the subreport parameters and the main report parameters at the same time.What I did was to present the parameters to the .rpt file which contains the main and sub reports. When I test by removing the sub-report then running the program, it works fine. But if I include the sub-report and pass parameters unto them theres this nagging &quot;invalid name&quot; error. There must be something wrong with what I'm doing...
 
Subreport parrameters are set seperately, as in:

'Create subreport database object, get table(s), login
set CRSubreports = session(&quot;oRpt&quot;).OpenSubReport(&quot;testsub.rpt&quot;)
set ReportDatabase2 = CRSubreports.Database
Set crdatabasetables2 = ReportDatabase2.tables
Set CRtable2 = crdatabasetables2.Item(1)
crtable2.SetLogonInfo &quot;ODBCDSNname&quot;, &quot;&quot;, cstr(userid), cstr(password)

'Get handles to parameters in SUB report (there are 2)
set Session(&quot;SubRptParamCollection&quot;) = CRSubreports.Parameterfields
Set ThisParam1 = Session(&quot;SubRptParamCollection&quot;).item(1)
Set ThisParam2 = Session(&quot;SubRptParamCollection&quot;).item(2)

'Set values for the parameters (these were previously set in the main report.
ThisParam1.SetCurrentValue cstr(&quot;paramvalue4&quot;),12
ThisParam2.SetCurrentValue cstr(&quot;paramvalue3&quot;),12

Try searching tek-tips, there are a few examples of doing this, this was stored in my database of examples.

-k
 
Thanks synapsevampire...will look it up...
 
Indeed that kind of attack works, synapsevampire!

I couldn't believe how easy it was. THANKS!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top