Skip to Content

Set default values as a function/query in Crystal Reports

Hi,


Is it possible to set default values as a function or a query for a command object parameter in CR2013?

I have two parameters in my report:

From_date & To_date

I need the From_date to be a week ago from today and the To_date to be yesterday.

I would ideally want them to be already set when the user opens the report.

OR

If the user does not provide a value for these parameters, the defaults should be set.

Any help you can give would be appreciated.


Regards.



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Nov 05, 2015 at 05:07 PM

    There is a way to do this in Crystal for Enterprise but not in "classic" Crystal such as CR 2013.

    Are you joining tables in your report or are you working off of a Command or a Stored Proc? If you're just joining tables, you can do this:

    1. Create the From_Date and To_Date parameters. Make them optional.

    2. Create the two formulas to get the default values for the dates.

    3. In the Select Expert, edit the formula and do something like this:

    (

    (HasValue({?From_Date}) and {MyTable.DateField} >= {?From_Date}) OR

    (not HasValue({?From_Date}) and MyTable.DateField = {@DefaultFromDate})

    )

    AND

    (

    (HasValue(({?To_Date}) and {MyTable.DateField} < {?To_Date}) OR

    (not HasValue({?To_Date}) and MyTable.DateField = {@DefaultToDate})

    )

    This would handle situations where only one date is entered as well as when no dates are entered.

    Unfortunately, you can't set parameters to Commands or Stored Procs as optional, so this doesn't work when those are used. So, instead, you have to put the command in a subreport, make the parameters optional in the main report, create formulas that return either the parameter value or the default date in the main report and use those to link to the appropriate parameters from the command in the subreport. However, this won't work if you already have subreports in your report because you can't nest subreports.

    -Dell

    Message was edited by: Dell Stinnett-Christy

    Add a comment
    10|10000 characters needed characters exceeded

    • Change your '=' to match what you're doing for the parameters. So, it will look like this:

      (

      (HasValue({?pFromDate}) and {table1.INVOICE_DATE} >= {?pFromDate}) OR

      (not HasValue({?pFromDate}) and {table1.INVOICE_DATE} >= {@DefaultFromDate})

      ) and

      (

      (HasValue({?pToDate}) and {table1.INVOICE_DATE} < {?pToDate}) OR

      (not HasValue({?pToDate}) and {table1.INVOICE_DATE} < {@DefaultToDate})

      )

      -Dell

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.