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
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.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Where and how do I set the 'Value' for a parameter?
Best regards,
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/
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
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;
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
Thanks for the reference, will read and see if it helps to solve the issue.