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!

Parameterized Report from ASP

Status
Not open for further replies.

Gragi

Programmer
Oct 4, 2004
59
US
Hi All,
I am trying to call a parameterized report from ASP. When I am trying to run the html and enter value and click Preview Report,
it's giving me an error like
An Error has occured. Please check the ASP page.
Error 13 Type mismatch

Can anybody tell me where the bug is?

in HTML
I have a textbox (txtMonth) and a Preview Report Button,
and Report is created in Crystal Report 9, with a parameter of data type string where I usally enter like 0501 (i.e JAN 05).

ASP page code:

<%@ Language=VBScript %>
<%
ReportName = MID(request.ServerVariables("PATH_TRANSLATED"), 1, (LEN(request.ServerVariables("PATH_TRANSLATED"))-18)) & "YrSales.rpt"

On Error Resume Next

If Not IsObject ( session("oApp") ) Then
Set session ("oApp") = Server.CreateObject("CrystalRuntime.Application")
End If

If IsObject(session("oRpt")) then
Set session("oRpt") = nothing
End if
Set session("oRpt") = session("oApp").OpenReport(ReportName,1)
session("oRpt").DiscardSavedData

If Request.Form("txtMonth") = "" Then
session("oRpt").ParameterFields(1).AddCurrentValue(0)
Else
session("oRpt").ParameterFields(1).AddCurrentValue(CInt(Request.Form("txtMonth")))
End If


If Err.Number <> 0 Then
Response.Write "An Error has occured. Please check the ASP page.<BR>"
Response.Write "Error " & Err.number & " " & Err.description
Else
If IsObject(session("oPageEngine")) Then
set session("oPageEngine") = nothing
End If
set session("oPageEngine") = session("oRpt").PageEngine
End If
Session("GroupTree") = Request.Form("chkGroupTree")
%>

<!-- #include file="SmartViewerActiveX.asp" -->


Thank You,
Gragi
 
Hi,
What are you entering for txtMonth?
Is the data field actually expecting a number..
Try it without the CInt() ..


[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Turkbear,
Actually I'm entering a string.

I got this working by changing lines

If Request.Form("txtMonth") = "" Then
session("oRpt").ParameterFields(1).AddCurrentValue(0)
Else
session("oRpt").ParameterFields(1).AddCurrentValue(CInt(Request.Form("txtMonth")))
End If

to just one statement

session("oRpt").ParameterFields.GetItemByName("Month").AddCurrentValue(CStr("cboMonth"))

now Iam able to view the report formatting, images, titles, but no database fields are showing up in the report.

What could be the problem?

Thank You,
Gragi
 
Hi,
Check your selection formula -
Perhaps no data matches what you are asking for..



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Hi,

In Select Expert I put like

{AllTable.Mon} = {?Month} OR
{?Month} = 'ALL'

and in DropDownlist I have options like
ALL, 0501, 0502... 0512

Do you think it is the issue of datatype?
In Crystal I put the parameter as String (checked Allow Multiple Values, as well Discrete Values(s).

Where as in ASP coding I put like CStr(cboMonth).

Thank You,
Gragi
 
Hi,
Somehow the above one is working

I changed the line in ASP code like
session("oRpt").ParameterFields(1).AddCurrentValue(CStr(Request.Form("cboMonth.SELECTED")))
and in Crystal Report the parameter I have selected only Discrete Value(S).

The thing is now it is working for one selected Item from the drop down list, now I am trying
to select more than one item from drop down list, so in crystal report I have checked the option
Allow multiple values.

So now in ASP what should we do now? I have read like we have to put
.EnableMultipleValues=1. So where should we place one?

Can anybody post the solution to this?

Thank You,

Gragi
 
'==================================================================
' WORKING WITH THE REPORT PARAMETER COLLECTION
'==================================================================

'Each report object which contains parameters has a collection called ParameterFields.
'That collection contains ParameterField objects (each parameter is one object).
'Each ParameterField object has properties and methods. We use those properties and methods
'to manipulate and set the values for the parameters through our ASP code.

'Before we can work with the properties and methods of the parameter we need to create a reference
'to the specific ParameterField Object. We reference this through the following hierarchy.
' Session("oRpt") - Report Object
' .ParameterFields - ParameterFieldsCollection
' .GetItemByName("name") - Gets ParameterField Object (identified by its name)
'This provides us with a handle to our ParameterField Object and allows us to use its properties
'and methods (ie. AddCurrentValue, EnableMultipleValues, DiscreetOrRangeKing)

'The following section shows setting single valued parameters of various data types.
Session("oRpt").ParameterFields.GetItemByName("ExampleStringParameter").AddCurrentValue(CStr("I am a string"))
Session("oRpt").ParameterFields.GetItemByName("ExampleNumberParameter").AddCurrentValue(CDbl("12345"))
Session("oRpt").ParameterFields.GetItemByName("ExampleBooleanParameter").AddCurrentValue(CBool("True"))
Session("oRpt").ParameterFields.GetItemByName("ExampleCurrencyParameter").AddCurrentValue(CDbl("10.3273"))
Session("oRpt").ParameterFields.GetItemByName("ExampleDateParameter").AddCurrentValue(CDate("2001/Jan/02"))
Session("oRpt").ParameterFields.GetItemByName("ExampleTimeParameter").AddCurrentValue(CDate("3:45:00 PM"))
Session("oRpt").ParameterFields.GetItemByName("ExampleDateTimeParameter").AddCurrentValue(CDate("2001/Jan/02 3:45:00 PM"))


'This section demonstrates the enabling of multiple values for a parameter and then setting
'a number of different values for that single parameter.
session("oRpt").ParameterFields.GetItemByName("ExampleMultiValuedStringParameter").EnableMultipleValues = 1
session("oRpt").ParameterFields.GetItemByName("ExampleMultiValuedStringParameter").AddCurrentValue(CStr("Anne"))
session("oRpt").ParameterFields.GetItemByName("ExampleMultiValuedStringParameter").AddCurrentValue(CStr("Nancy"))
session("oRpt").ParameterFields.GetItemByName("ExampleMultiValuedStringParameter").AddCurrentValue(CStr("Laura"))
session("oRpt").ParameterFields.GetItemByName("ExampleMultiValuedStringParameter").AddCurrentValue(CStr("Justin"))
session("oRpt").ParameterFields.GetItemByName("ExampleMultiValuedStringParameter").AddCurrentValue(CStr("Margaret"))
session("oRpt").ParameterFields.GetItemByName("ExampleMultiValuedStringParameter").AddCurrentValue(CStr("Steven"))
session("oRpt").ParameterFields.GetItemByName("ExampleMultiValuedStringParameter").AddCurrentValue(CStr("Albert"))


'This section shows enabling a parameter to accept a ranged parameter.
'The first line sets the DiscreetOrRangeKind to 1. For Ranged parameters the constant is 1.
'The second line uses the AddCurrentRange method which takes three arguments.
' AddCurrentRange LowerBoundValue, UpperBoundValue, CRRangeInfoConstant
'The CRRangeInfoConstant of 3 indicates that the range should include values greater than or equal to
'the lower bound and less than or equal to the upper bound.

session("oRpt").ParameterFields.GetItemByName("ExampleRangedNumberParameter").DiscreteOrRangeKind = 1
session("oRpt").ParameterFields.GetItemByName("ExampleRangedNumberParameter").AddCurrentRange CDbl("5"),CDbl("10"),CDbl("3")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top