Solved

CR10 / VB.NET : RefreshReport Keeps Asking for Parameter Entry

Posted on 2004-07-30
13
2,588 Views
Last Modified: 2008-01-09
Hi All,

I've created a custom toolbar for the Report Viewer and having difficulty with the RefreshReport option always asking to enter the parameters required for the report.

When i first load the report, it doesn't ask because i have added the values as discreet values, code as follows:

... ... ...
            ' Set Discreet value to the entered integer
            pdvStockLessThan.Value = txtLowStockVariable.Text

            ' Add Discreet Value to Value Collection
            pvCollection.Add(pdvStockLessThan)

            ' Apply Value Automatically to Report
            rptLowStock.DataDefinition.ParameterFields("StockLevel").ApplyCurrentValues(pvCollection)

            ' Clear Collection and prepare for next parameter if any
            pvCollection.Clear()

            ' Set the report source for the crystal reports
            ' viewer to the report instance.
            ReportViewer.ReportSource = rptLowStock

            ' Zoom viewer to fit to the whole page so the user can see the report
            ReportViewer.Zoom(100)

            ' Get Report Page Count
            PageCount = rptLowStock.FormatEngine.GetLastPageNumber(New CrystalDecisions.Shared.ReportPageRequestContext)
... ... ...

Report Loads fine with the correct value as stated in the text box's default entry.

The problem here is that when i click on the Refresh button which in turn calls the RefreshReport sub, it pops up asking to enter the parameter which in this case, is the StockLevel Parameter

The following is the code that i've currently got for the refresh button (which i have tried multiple commands with the code to try and solve this) but to no avail.

Current Refresh Button Code:

    Private Sub tbnShowRefresh_Activate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbnShowRefresh.Activate
        ' Clear Collection and prepare for next parameter if any
        pvCollection.Clear()

        ' Set Discreet value to the entered integer
        pdvStockLessThan.Value = txtLowStockVariable.Text

        ' Add Discreet Value to Value Collection
        pvCollection.Add(pdvStockLessThan)

        ' Apply Value Automatically to Report
        rptLowStock.DataDefinition.ParameterFields("StockLevel").ApplyCurrentValues(pvCollection)

        ReportViewer.ReportSource = rptLowStock
        ReportViewer.RefreshReport()
        UpdatePageNumber()
    End Sub

No matter what i try it keeps asking for the parameters... I cant seem to find something that'll help me avoid this

Anyone out there got an answer for me?

Many thanks in Advance

Ray.
0
Comment
Question by:RayFrangie
  • 5
  • 2
  • 2
  • +3
13 Comments
 
LVL 10

Expert Comment

by:ebolek
ID: 11677528
o. why dont you hold the values when the user first enters it, and then put the same code to the
refresh reprort event,

 Set Discreet value to the entered integer
        pdvStockLessThan.Value = txtLowStockVariable.Text

        ' Add Discreet Value to Value Collection
        pvCollection.Add(pdvStockLessThan)

        ' Apply Value Automatically to Report
        rptLowStock.DataDefinition.ParameterFields("StockLevel").ApplyCurrentValues(pvCollection)
This wioll automatically set the values again, and wont ask you the prompt box.This is the nature of crystal reports. Hold the valuies and set them back gaain in the refresh event

Regards
Emre
0
 
LVL 1

Author Comment

by:RayFrangie
ID: 11677581
Hi ebolek,

The value in the textbox will be changed by the user at runtime, and on clicking the refresh button, i need it to refresh the report with the new parameters.

Unless i'm doing something wrong (which is where i need your help :-) ) it keeps popping up with the Enter Parameter Values Dialog Box.

Hope this adds more light at the end of the tunnel

Thanks in advance

Ray.
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11677607
that is fine. Put the same code in the refresh event but dont clear the values collection. Restore the values that user enters to the text box and then set the values to it.
0
 
LVL 1

Author Comment

by:RayFrangie
ID: 11677668
ebolek,

Just tried your advice... same thing

Here's the code of the updated refresh event, maybe this will help:

    Private Sub tbnShowRefresh_Activate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbnShowRefresh.Activate
        ' Set Discreet value to the entered integer
        pdvStockLessThan.Value = txtLowStockVariable.Text

        ' Add Discreet Value to Value Collection
        pvCollection.Add(pdvStockLessThan)

        ' Apply Value Automatically to Report
        rptLowStock.DataDefinition.ParameterFields("StockLevel").ApplyCurrentValues(pvCollection)

        ReportViewer.ReportSource = rptLowStock
        ReportViewer.RefreshReport()
        UpdatePageNumber()
    End Sub


Thanks in Advance.

Ray.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 11677968
Ray,

Is the refresh button being clicked the one on the crystal viewer or is it your own form button?

frodoman
0
 
LVL 1

Author Comment

by:RayFrangie
ID: 11678005
Frodo,

Its my own one.... (The crystal toolbar looks like crap so i brought it to life a little :P ) The code in the above post is the code for the Refresh Button.

I'm using the RefreshReport Command to refresh the report.



Ray.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 42

Expert Comment

by:frodoman
ID: 11678156
Ray,

Unfortunately as far as I know there's no simple way to do what you want.  I've been involved in some previous discussions and that's been the result every time (example: http://www.experts-exchange.com/Databases/Crystal_Reports/Q_20944952.html ).

The only way I've heard of someone working around this is to have their own refresh button fire off a process that saves the current parameter values, closes the form containing the CR viewer, then opens a new instance of the form and kicks off the "new report" process.  Basically instead of refreshing you completely close the report and start over with the saved parameter values.  Of course this assumes that you're using a subform for your viewer and it isn't in your application's main form.

This isn't a great solution of course, but it's the only one that I've heard of being used successfully.  

Good luck,

frodoman
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 11679612
I agree with frodoman.  The RefreshReportCommand is set to delete the parameters and prompt for new ones.

mlmcc
0
 
LVL 1

Author Comment

by:RayFrangie
ID: 11683052
Hi Guys,

I was looking into it last night and had a look at the members for the CrystalReportViewer as seen here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlrf/html/crlrfwindowsformscrystalreportviewermemberstopic.asp

It seems like there's a ReportRefresh Event which should fire when the report is refreshed (Which in theory should fire when the CrystalReportViewer.RefreshReport. command is used). Any one tried using this event to do what i'm after? I havent tried it yet, i will later on though...

Any info is more than welcome

Many thanks

Ray.
0
 
LVL 13

Accepted Solution

by:
EwaldL earned 500 total points
ID: 11684121
the behaviour you see with the RefreshReport method is by design.  msdn describes if functionality as follows on
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlrf/html/crlrfwindowsformscrystalreportviewerclassrefreshreportmethodtopic.asp

"This method will refresh the data for the report currently displayed in the viewer. Any parameters or logon information, needed by the report, will be prompted for."

So instead I would try to refresh the report itself (not the viewer), pass the parameters to it and then pass the report to the viewer.

something like this

rptLowStock.Refresh()
rptLowStock.SetParameterValue("StockLevel", "YourValue")
ReportViewer.ReportSource = rptLowStock
0
 
LVL 1

Author Comment

by:RayFrangie
ID: 11684762
EwaldL,

Perfect... Exactly what i wanted...

Loads the report perfectly, does not ask for a parameter, you hit the nail on the head. 500 Points to you.

Many thanks to all, hope you all learnt something new just like i did

Once again, many thanks

Regards,

Ray.
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 11684991
nice one, good to hear it's working for you now! :-)
0
 

Expert Comment

by:joshsteiner
ID: 11907626
the problem with EwaldL's solution (which is what i did first) is that assigning a new reportsource to a viewer seems to tear down the whole widget and spawn a new on (behind the scenes, watch with your debugger)... ie: its painfully slow and has some nasty flash as it destroys the existing widget.  whereas if you use the viewers refresh button/method, its much quicker and slicker.  i have 6 charts embeded in my app, and hence the slowness is multiplied by 6, so i really need to find a way to set the parameter in the current existing report in the viewer... any hope?

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now