Results 1 to 13 of 13

Thread: Passing parameters

  1. #1

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    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:
    1. Report = New repProductivity
    2.  
    3.         ''Get the collection of parameters from the report
    4.         crParameterFieldDefinitions = Report.DataDefinition.ParameterFields
    5.         ''Access the specified parameter from the collection
    6.         crParameterFieldDefinition = crParameterFieldDefinitions.Item("pTitle")
    7.  
    8.         ''Get the current values from the parameter field.  At this point
    9.         ''there are zero values set.
    10.         crParameterValues = crParameterFieldDefinition.CurrentValues
    11.  
    12.         ''Set the current values for the parameter field
    13.         crParameterDiscreteValue = New ParameterDiscreteValue
    14.         crParameterDiscreteValue.Value = "My parameter value."
    15.  
    16.         ''Add the first current value for the parameter field
    17.         crParameterValues.Add(crParameterDiscreteValue)
    18.  
    19.         ''All current parameter values must be applied for the parameter field.
    20.         crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    21.  
    22.         Report.SetDataSource(rsData)
    23.         CRViewer.ReportSource = Report
    24.         CRViewer.RefreshReport()

  2. #2
    Lively Member
    Join Date
    Dec 2004
    Posts
    121

    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.

  3. #3

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    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.

  4. #4
    Lively Member
    Join Date
    Dec 2004
    Posts
    121

    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.

  5. #5

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    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:
    1. rsData = dbStList.OpenRecordset("select * from report order by print_order")
    2.         Report = New repProductivity
    3.  
    4.         crParameterFieldDefinition = Report.DataDefinition.ParameterFields.Item("pTitle")
    5.         crParameterValues = Report.DataDefinition.ParameterFields.Item("pTitle").CurrentValues
    6.         crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    7.         crParameterDiscreteValue.Value = "Parameter Text."
    8.         crParameterValues.Add(crParameterDiscreteValue)
    9.         crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

    and then the 2nd time, when i refresh the report using the following code:
    VB Code:
    1. CRViewer.RefreshReport()

    Wht could be the prob??

  6. #6
    Lively Member
    Join Date
    Dec 2004
    Posts
    121

    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.

  7. #7

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    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

  8. #8
    Lively Member
    Join Date
    Dec 2004
    Posts
    121

    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.

  9. #9

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: Passing parameters

    Quote 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.

  10. #10
    Lively Member
    Join Date
    Dec 2004
    Posts
    121

    Re: Passing parameters

    This is how I do it:

    VB Code:
    1. rptName.SetDataSource(ds)
    2. [B]rptName.SummaryInfo.ReportTitle = "Report Name From:  " & Format(dtpBeginDate.Value, "MM/dd/yyyy") & " to " & Format(dtpEndDate.Value, "MM/dd/yyyy")[/B]
    3.  
    4. frmCRViewer.CrystalReportViewer1.ReportSource = rptName
    5.  
    6. 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.

  11. #11

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    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.

  12. #12
    Lively Member
    Join Date
    Dec 2004
    Posts
    121

    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!

  13. #13
    Member
    Join Date
    Jul 2005
    Posts
    36

    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:
    1. 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
  •  



Click Here to Expand Forum to Full Width