Skip to Content
avatar image
Former Member

Crystal Reports not Passing current date to subreport

Dear experts, I am trying to pass the current date values to parameters in a Crystal Report that feeds a sub-report but the following code does not make the change intended:

// {?FiscalYear} default value is 9999

If {?FiscalYear} = 9999 then {?FiscalYear} = Year(CurrentDate); {?FiscalMonth} = Month

(CurrentDate); Else...

It does not fail with any error message but it doesn't bring out any data either. When checked the value of {?FiscalYear} is unchanged = 9999.

What am I doing wrong?

Thank you!

erollano

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Apr 11, 2017 at 08:13 AM

    If this is in your select statement

    If {?FiscalYear} = 9999 then {?FiscalYear} = Year(CurrentDate); {?FiscalMonth} = Month

    (CurrentDate); Else...

    It will not work as its not filtering any data. If its a formula you need to show all text and explain how you plan to use it to filter data in Subreport

    Ian

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 11, 2017 at 03:52 PM

    My apologies.

    {?FiscalYear} is a parameter type Number that users can change it to any valid year i.e.: 2017 so this value passes to the sub-report to bring in the data for that year.

    The intention here is, by setting the Parameter to 9999 as Default, enable it to change automatically to Current Year if no change was made.

    So this is the current Record Selection formula, where dates @CurrentYear and @CurrentMonth where converted values (ToNumber(Year(CurrentDate) and ToNumber(Month(CurrentDate):

    If {?FiscalYear} = 9999 then ( {?FiscalYear} = @CurrentYear; ; {?FiscalMonth} = @CurrentMonth; ) Else...(the regular selection with an entered year and month values)

    It does not fail with any error message but it doesn't bring out any data either. When checked the value of {?FiscalYear} is unchanged = 9999 (it should be 2017 which is the value in @CurrentYear, and brings back no valid data.

    Hope this is clearer now.

    Thanks,

    Erollano

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 11, 2017 at 04:05 PM

    But you are still not filtering any data

    Select statement should look like..

    (If {?FiscalYear} = 9999 then {FiscalYearField} = @CurrentYear else {FiscalYearField} ={?FiscalYear})

    and

    (If {?FiscalYear} = 9999 then {FiscalMonthField} = @CurrentMonth else {FiscalMonthField} ={?FiscalMonth}))

    and ... remaining select filters

    Ian

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 12, 2017 at 03:42 PM

    Ian,

    Not sure where you are going with this, but I am not trying to filter any data but test the in Selection Record formula, the user's input -say 2016 but if the user left the default, 9999, then load the {?FiscalYear} with the current year.

    e

    Add comment
    10|10000 characters needed characters exceeded