Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: print each calendar date between 2 dates Post Reply Post New Topic
Author Message
epement
Newbie
Newbie
Avatar

Joined: 27 Mar 2012
Location: United States
Online Status: Offline
Posts: 6
Quote epement Replybullet Topic: print each calendar date between 2 dates
     Posted: 27 Mar 2012 at 1:01am
I am really stuck on this one and need some help. I am using Crystal Reports 2008 querying a single table. Each record contains a StartDate and an EndDate. My task is this:

For each selected record, I need to generate additional, separate rows for each calendar day in the date range  (including the endpoint). Each  row must contain the calendar date and two other fields from that record. E.g., if StartDate is Feb 28, 2012 and EndDate is March 3, 2012, five new rows should be generated (recognizing that Feb 29 is a leap year).

I have tried several different loop control structures, but I always wind up with only one row with the word "True" in a field where I expect a date. Please help!!


Edited by epement - 27 Mar 2012 at 1:02am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Mar 2012 at 11:02am
how about another source table of all calendar dates.
you can join the two together to get the full data set you want
IP IP Logged
epement
Newbie
Newbie
Avatar

Joined: 27 Mar 2012
Location: United States
Online Status: Offline
Posts: 6
Quote epement Replybullet Posted: 28 Mar 2012 at 3:06am
Thanks for the suggestion of using another source table to get a list of valid dates. However, using a separate table of all the calendar days in a year seems contrary to what Crystal is capable of. Crystal is innately able to recognize a valid date for any given year.

I finally cobbled together a "hack" solution that does give me multiple rows of data, one for each day in the date range. And it kinda works, but it's not pretty.

In the Details section I put a function that prints multiple output rows. I right-click on the function name, select "Format Field" and in Common, I checked the box that says "Can grow." And it seems to work.

The function looks like this:
WhilePrintingRecords;
local stringvar dateList := "";
local datetimevar aDate := {StartDate};

while aDate <= {EndDate} do
(
    if dateList = ""
    then
        ( dateList := ToText({My_ID}) + "      " + ToText({Fname})
                      + "       " + left(totext(aDate),10) )
    else
        ( dateList := dateList + ChrW(13)+ChrW(10) + ToText({My_ID}) + "      "
                      + ToText({FName}) + "       " + left(ToText(aDate),10) );
    aDate := dateadd("d",1,aDate);
);
dateList

Note that "ChrW(13)+ChrW(10)" are the codes for CR and LF, which is how I was able to build a multi-line block.

The problem is that I cannot position the fields within the output by graphical dragging, cannot apply formatting codes, etc. So although it technically "works", I don't consider it the best solution.

So what kind of solution would permit individual formatting of the fields on the lines? Thanks for any help.

.

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Mar 2012 at 4:00am
I would disagree that adding another table is contrary to what crystal is capable of. Using the 'right' tables to get the the 'right' data set is fundamental to any report.
Crystal has some abilities to help accomplish your desired output if you cannot get the data set as you need it but I would think of that as the work around not the best solution. Just my opinion...
Anyway, your solution (which is what I have also used in some reports) does not give you a full data set of what you want but rather tries to mimic it by expanding a single row to appear as if it were multiple rows. My suggestion was to try to give you a solution that did have a full data set so that you could do the other things your report needs (like formatting).
One way I have dealt with this in the past is to create multiple detail sections. My report required black font for records that existed and red font for ones that were missing. I used a similar formula field to "only create mssing records" ( make a text box with dates strings). I placed the original fields formatted in black ink on detail a and the missing record formual in red ink on detail b.
My requirements mighthave been a little more complex but the design idea might give you something to work with.
 


Edited by DBlank - 28 Mar 2012 at 4:01am
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum