|
-
Mar 15th, 2005, 06:55 AM
#1
Thread Starter
Fanatic Member
Passing parameters
I am writing the following code to pass a value to the parameter field. But while running the appl... it asks for the value for the same!!! Why so?
VB Code:
Report = New repProductivity
''Get the collection of parameters from the report
crParameterFieldDefinitions = Report.DataDefinition.ParameterFields
''Access the specified parameter from the collection
crParameterFieldDefinition = crParameterFieldDefinitions.Item("pTitle")
''Get the current values from the parameter field. At this point
''there are zero values set.
crParameterValues = crParameterFieldDefinition.CurrentValues
''Set the current values for the parameter field
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = "My parameter value."
''Add the first current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue)
''All current parameter values must be applied for the parameter field.
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
Report.SetDataSource(rsData)
CRViewer.ReportSource = Report
CRViewer.RefreshReport()
-
Mar 15th, 2005, 04:10 PM
#2
Lively Member
Re: Passing parameters
I'm not sure if I understand your question.
But did you set the crystal report up to prompt for the parameter by adding it in the formula field when you were building the report? If yes, that's where it's coming from.
Another place it could be coming from is if you are querying an Access database that has the query set up to prompt for the parameter.
-
Mar 16th, 2005, 02:01 AM
#3
Thread Starter
Fanatic Member
Re: Passing parameters
where can i find the setting to prompt for the parameter. I have just added a parameter field named pTitle and placed it on the report page. and thru vb i am trying to add value to that parameter field. thats it.
-
Mar 16th, 2005, 09:00 AM
#4
Lively Member
Re: Passing parameters
You can write the crystal query with a formula to prompt for a parameter. For instance, if inserted a field in a report and wrote a formula such as
{customer.name} = {?customer.name} Your crystal report would prompt for the parameter.
From your post I interpreted what you said to be that you were being prompted for the parameter twice. I thought it might because you had the parameter prompt in code and in the query. But, from your response, it doesn't sound like this is your problem.
You should pass parameters through VB.net code like you are trying to do.
-
Mar 16th, 2005, 10:30 AM
#5
Thread Starter
Fanatic Member
Re: Passing parameters
i am not using any crystal query.
i am prompted 2wice while running the applicaiton.
1st time, when my frmReport is loaded, which is having the CRViewer control.
then following codes are executed
VB Code:
rsData = dbStList.OpenRecordset("select * from report order by print_order")
Report = New repProductivity
crParameterFieldDefinition = Report.DataDefinition.ParameterFields.Item("pTitle")
crParameterValues = Report.DataDefinition.ParameterFields.Item("pTitle").CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = "Parameter Text."
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
and then the 2nd time, when i refresh the report using the following code:
Wht could be the prob??
-
Mar 16th, 2005, 12:19 PM
#6
Lively Member
Re: Passing parameters
If you are refreshing the report I believe it's running through the whole query again which is why it's prompting you twice. Just a guess, I don't pass parameters to Crystal the same way you do.
-
Mar 17th, 2005, 02:08 AM
#7
Thread Starter
Fanatic Member
Re: Passing parameters
Thats right... when I am refreshing the report, the parameter value which I set thru VB is overwritten by the prompt from CR. I removed the code to refresh and the parameter value is displayed perfectly in the report.
Now the question is how to remove the prompt while loading or refreshing the report; coz the user may refresh the report by clicking the refresh button. That time i dont want to pop up the prompt for the parameter field
Regards
-
Mar 17th, 2005, 09:08 AM
#8
Lively Member
Re: Passing parameters
Again, I don't pass parameters the way you do. I tested what you were describing and when I refreshed the report manually hitting the refresh button, it didn't ask me for the parameters again. My parameters persist because I send them to a sql statement that produces a dataset that I display on the report. Maybe that's how you should do it? You are passing your parameters directly to your Crystal Report.
Last edited by Malim; Mar 17th, 2005 at 10:27 AM.
-
Mar 18th, 2005, 01:52 AM
#9
Thread Starter
Fanatic Member
Re: Passing parameters
 Originally Posted by Malim
Again, I don't pass parameters the way you do. I tested what you were describing and when I refreshed the report manually hitting the refresh button, it didn't ask me for the parameters again. My parameters persist because I send them to a sql statement that produces a dataset that I display on the report. Maybe that's how you should do it? You are passing your parameters directly to your Crystal Report.
I am also doing the same way. You are passing a dataset to display the report and passing a recordset. That doesnt make any difference. The parameter field, which I am using is just to display the heading on the report. Its just "Report from xx/xxx/xxxx to xx/xx/xxxx". Thats all.
-
Mar 18th, 2005, 08:41 AM
#10
Lively Member
Re: Passing parameters
This is how I do it:
VB Code:
rptName.SetDataSource(ds)
[B]rptName.SummaryInfo.ReportTitle = "Report Name From: " & Format(dtpBeginDate.Value, "MM/dd/yyyy") & " to " & Format(dtpEndDate.Value, "MM/dd/yyyy")[/B]
frmCRViewer.CrystalReportViewer1.ReportSource = rptName
frmCRViewer.Show()
Then I go to the crystal report and right click in white space and add the special field "Report Title". The Report Title field is replaced with the Report Title from above at runtime.
Last edited by Malim; Mar 18th, 2005 at 09:02 AM.
-
Mar 18th, 2005, 09:06 AM
#11
Thread Starter
Fanatic Member
Re: Passing parameters
Thanx buddy, you solved my problem. It was elementray, but I didnt find it. I was under the impression that I have pass the title text using parameter field only. I was wrong.
Thanx again.
-
Mar 18th, 2005, 09:37 AM
#12
Lively Member
Re: Passing parameters
No problem. Sometimes the easiest things are the hardest to figure out because there is so much documentation to wade through. That's why this forum is so awesome!
-
Sep 21st, 2005, 10:06 AM
#13
Member
Re: Passing parameters
Hey guys, nice posts! But, i have more questions.
Malim, PVBangera,
This is whats happening with me: (Sorry, I have been looking all around now I am getting )
I am opening the report from vb6.
I pass the record set from vb using
VB Code:
oReport.Database.SetDataSource RecSet
Now, the crystal report does not have any formula fields that use the parameters. The stored proc in the report does use parameters. So, I see 'Parameters' group on the crystal report (Design mode).
My problem is, after passing the recordset, CR still prompts for Parameters. I am soo frustrated!
How can I get rid of those parameters.
(These parameters are strictly used for stored proc. They are not being used in any of the fields.)
Your Help will be appreciated very much!
Thanks Guys!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|