Home RAP

How to set calculated date in Parameter default value?

Hi,

I often have reports that have a DateFrom and DateTo parameter for the user to enter. What I need to do is calculate the start and end of the previous month and have these values as the default for the two parameters.

How can this be done please?

Best regards,

Bruce

Comments

  • Hi Bruce,

    You can assign default values to your parameters using the Value property. Take a look at the DateUtils unit in Delphi for how to calculate the start of a month and end of a month. Specifically the StartOfTheMonth and EndOfTheMonth routines.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Nico,

    Where and how do I set the 'Value' for a parameter?

    Best regards,

    Bruce
  • Hi Bruce,

    When creating a report parameter in the Report Tree of the designer, you can click on the newly created parameter and assign its Value or Values property in the object inspector. Generally report parameters are tied to a search condition in DADE so it's best to create the parameter first, then define the search condition. See the following article for more information.

    http://rbwiki.digital-metaphors.com/end-user/fundamentals-end-user/report-parameter-fundamentals/


    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Bruce: Assuming you only have one autosearch field, this will assign the previous month to it:

    var
    cStart : String;
    cEnd : String;
    Day, Month, Year : Integer;
    begin
    DecodeDate(CurrentDate, Year, Month, Day);
    if (Month = 1) then
    begin
    cStart := '12/1/'+ IntToStr(Year-1);
    cEnd := '12/31/'+ IntToStr(Year-1);
    end
    else
    begin
    cStart := IntToStr(Month-1) +'/1/'+ IntToStr(Year);
    cEnd := DateToStr(StrToDate( IntToStr(Month) +'/1/'+ IntToStr(Year) )-1);
    end;
    Report.AutoSearchFields[0].SearchExpression := cStart+','+cEnd;
    end;
  • Frankp01,

    Many thanks for your detailed piece of code - I will give this a try. Just need to find out where to place it in the report which is the issue I have most of the time. J
  • Nico,

    Thanks for the reference, will read and see if it helps to solve the issue.
Sign In or Register to comment.