cancel
Showing results for 
Search instead for 
Did you mean: 

Do NOT show Parameter prompt when loading report

Former Member
0 Kudos

Hello,

I know there are a million threads on this topic, but that's the problem...it's impossible to find an answer.  So apologies in advance if it's out there already.

I have a generic report viewer page/control in my application where I load a variety of reports; I do not know what the parameters are in advance.  In ALL cases, I do NOT want to be prompted for parameters when the report is first loaded.  I want the report to use either empty values or any specific values I pass in via code when the report is first loaded and executed in the Viewer.

In one example, the report has one string parameter and 2 numeric parameters.  If I set the string parameter to "", then handle that in my record selection criteria, that is an OK workaround.  But for the numeric parameters, I want to set them to null or nothing and then not be prompted.  This is where I'm having difficulty: If I do nothing, I get prompted. If I set them to Null/Nothing, I'll get an error message when the report loads that there is a data type mismatch.  ALL of the parameters are set to OptionalPrompt=True.  Also, if I set EnableParameterPrompt="False", I receive an error that parameters are missing even though all parameters are Optional.  So the main issue is to be able to set numeric (and date) prompt values to something in code that will then stop them from being prompted in the Report Viewer when the report loads.

Thanks in advance for a solution or a pointer to another thread with the solution.

Richard

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Richard,

Have you tried setting them to NULL, anything other than null is a value? Same as when you select them in CR Designer.

Don

Former Member
0 Kudos

Thank you again Don.  As I mentioned above, I set the parameter values to Null/Nothing (in VB it's Nothing) at run time and I get an error message when the report loads that there is a data type mismatch for the parameter, since it's expecting a number.

What seems odd to me is that if I set EnableParameterPrompt="False", this should do what I want - not display the parameter prompt.  The problem is that throws an error when the report loads that parameters were not provided, even though OptionalPrompt=True for all parameters.  Is there a way I can use EnableParameterPrompt="False" and not cause the report viewer to throw an error?  Is this a bug or am I using these settings incorrectly?

Since by default I want the report's full results set returned (without the initial parameter prompt!), I could set the Default Values of the parameters to Null (in the CR designer for the parameters; currently I'm leaving Default Values empty for all numeric parameters which to me also makes sense - for the String Parameters it's based on a dynamic list of values, so no Default Values property is available for the string parameter), then at run time ensure those Null values are used as parameter values so no prompt occurs.  Can you let me know how this would be possible and the value I would use for String, Date and Numeric parameters to specify that the default value is Null in the CR Designer?

Or alternatively, what I really want to do is to set HasValue=False for all parameters but still NOT get the prompt, since for all parameters OptionalPrompt=True.  Again it seems on the surface that I should be able to use EnableParameterPrompt="False" with OptionalPrompts=True and not cause the report viewer to throw an error.

Thanks again,

Richard

0 Kudos

Hi Richard,

If you hit refresh in the Designer does it prompt for parameters?

The LOV could be the source of the problem, it's a separate query to get the values from the DB, this could be the problem also.

Can you attach the report without saved data?

Don

Former Member
0 Kudos

Hi Don,

In the Designer, when I first click Main Report Preview, I am prompted for parameters.  When I click Refresh in the Designer, I am prompted to "Use current parameter values" or "Prompt for new parameter values".

This editor does not let me attach a .RPT file.  Any ideas on how I can get the Rpt file to you?

Thanks again for your help.

Richard

0 Kudos

You have to click on the Advanced Editor button to be able to add attachment.

Export to RPT format, saves data, now open that up in Viewer and hit refresh. Does it prompt if you have use Parameters in the Viewer properties?

Don

Former Member
0 Kudos

Hi Don,

When I do as you requested, I still get prompted.  This is true both standalone as well as when I try to open up the report in the viewer from my application.

I am using the Advanced Editor and the allowed file types are "File types allowed: .asc, .txt, .text, .xml, .xsl, .gif, .png, .jpeg, .jpg, .jpe, .ics ".

Thanks,

Richard

0 Kudos

rename the report to *.txt and attach.

Opening the report in the Report Designer built into the VS IDE is not valid test. It's the old ActiveX viewer and is not used in realtime application.  Must test while running your app.

Are the Parameters part of a Stored Procedure?

Try removing the LOV and see if it still prompts.


Former Member
0 Kudos

Here are the reports attached; the one without data I am using in my application, and the one with the data as you instructed.

If I remove the String Parameter (that is using the Dynamic LoV) then I'm still prompted for the numeric parameters that do not use an LoV.

Thanks

Former Member
0 Kudos

Hi Don, any way you can help me on this?  Were you able to access the reports I uploaded?  Thanks, Richard

0 Kudos

Hi Richard,

Sorry, Phone cases come first. I can open the report up with OUT it prompting so check your code.

Also, open the report and go into Report Options and uncheck Verify on first refresh.

That may cause it to prompt. Getting the collection shows exactly what you have in the report also so no surprises there:

Center: Dynamic Cascading Parameter ( LOV )

Based on field: Enter Center:

InstrumentID: Crystal Parameter

Based on field: {?InstrumentID}

SequenceNumber: Crystal Parameter

Based on field: {?SequenceNumber}

Also noted the page is set to 8 1/2 by 11 but the page layout in CR Designer the page does go over the edge so you may want to adjust the paper size. Change the Margins in Page Setup, it's because CR will set the default margins to 1/4 inch if you don't adjust and the printer does not return a valid margin value from the driver.

See if this helps

Don

Former Member
0 Kudos

Hi Don, thanks again.

I don't understand the comment "I can open the report up with it prompting so check your code." - this is what I do NOT want to happen...I can do that too.

I did the other adjustments you recommended - uncheck "Verify on first refresh" and fixed the page settings.  It still prompts under all scenarios.

Have you been able to open the report WITHOUT it prompting?

Thanks,

Richard

0 Kudos

Hi Richard,

Sorry that was a typo, I updated it. No it does NOT prompt when I open the report:

If I open the report with saved data it doe snot prompt obviously.

When I open the report without data it does prompts when I hit the Preview button in my app but not when I simply open it, and this is what I see:

SO I'm still missing something....

Can you create a simple app that emulates what you are doing so I can see how your doing this in code?

Use this extreme.mdb file as your data source, renamed to *.txt, so unzip it and rename it back to extreme.mdb.

In the properties of the viewer try setting this option to True or False and see if that helps:

Don

Former Member
0 Kudos

Hi Don,

OK, here is where I'm at:  If I set a value for each of the three parameters in the report before loading it as the ReportSource, it does not prompt.  Here is how I'm setting each of the parameters (just one of three examples provided):

                        rptDoc.ParameterFields("Center").CurrentValues.Clear()
                        rptDoc.ParameterFields("Center").CurrentValues.AddValue(InstrumentOwnerName)
                        rptDoc.ParameterFields("Center").HasCurrentValue = True

If I try this:

     rptDoc.ParameterFields("Center").CurrentValues.AddValue(Nothing) ' VB Nothing = c# Null

I get a data type error whether it's for a string or numeric field, and the report does not load.

If I comment the "CurrentValues.Clear()" and "AddValue" lines and just set HasCurrentValue = True, I still get prompted.

In summary, I can only force a prompt to not be displayed for a parameter only if I assign it a value through the "AddValue" method, even though in the report definition for all of these parameters, the setting OptionalPrompt=True.  It seems like I should be able to set the parameter field to some value so that the viewer thinks it has a value and doesn't prompt, yet still returns all records (a "don't care" value).

Thanks for any more thoughts.

Regards,

Richard

0 Kudos

Ah, .Add is to add a new parameter that would be why it errors.

You want to use the .Modify.... Or Set as below.

This format may work for you also:

rpt.SetParameterValue("Center", Convert.ToSingle(InstrumentOwnerName));

And of course the Convert. has all types.

And an FYI, how to tell if the Parameter is Dynamic:

public Boolean isParameterDynamic(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt, int iCnt, bool YorN)

{

    if (rpt.DataDefinition.ParameterFields[iCnt].Attributes != null && rpt.DataDefinition.ParameterFields[iCnt].Attributes.ContainsKey("IsDCP"))

    {

        Hashtable objAttributes = rpt.DataDefinition.ParameterFields[iCnt].Attributes;

        YorN = (Boolean)objAttributes["IsDCP"];

        return YorN;

    }

    return YorN;

}

Don

Former Member
0 Kudos

Hi Don,

Again, thanks as always.  I'm not getting errors setting the values (whether string or numeric) - that is always working fine.  The error was only happening if I tried to set a value to null/nothing.

Even when I wasn't using AddValue, I was still being prompted.  If I use SetParameterValue instead, to what values can I set the parameters, without them erroring, so that no prompt occurs and all report records are returned?  For me there is a simple workaround for string parameters (I can check the value for "" when building the recordset filter) but what can I do for numeric and date parameter types?

Thanks again,

Richard

0 Kudos

Try setting them to Null using that API.


former_member183750
Active Contributor
0 Kudos

This KBA may help with the NULLs:

1214841 - How to pass a NULL parameter value at runtime using Visual Studio .NET

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Answers (0)