I need to get a count by the dates in my date range for patients that were admitted on the dates in the date range. In other words if Bob Jones was admitted on 08/01 and discharged on 08/15 and my data selection is for 08/05 through 08/20 Bob Jones would not be counted on 08/01 - 08/04 and be counted on 08/05, 08/06, 08/07, etc through his discharge date of 08/15 and not be included in the count for 08/16 - 08/20.


I created a formula and put it in the header of my report that would set-up my date array.
Shared StringVar StartParmYMD;
Shared StringVar EndParmYMD;

Shared StringVar Array EachDay;
Shared NumberVar D := 0;

NumberVar NumberDays := (CDbl(EndParmYMD) - CDbl(StartParmYMD)) + 1;
NumberVar StartDay := CDbl(StartParmYMD)-1;

//Build the array of the days in the start/end parameters...
For D := 1 to NumberDays Do
(
Redim Preserve EachDay[D];
StartDay := StartDay + 1;
EachDay[D] := CStr(StartDay,0,"") + " #0" //I added the this because I was going to start my count after the #
)



Then on the detail line for each patient, because they only appear on the report just once, not for everyday that they are admitted I put this formula:
WhilePrintingRecords;
Shared StringVar StartParmYMD;
Shared StringVar EndParmYMD;

Shared StringVar Array EachDay;
Shared NumberVar D := 0;

// How many days between the selected start/end days...
NumberVar NumberDays := UBound(EachDay);
NumberVar StartDay := CDbl(StartParmYMD)-1;


NumberVar PatCountN;
StringVar ArrayDay;

// Admit/Discharge dates for the patient...
StringVar PatStartDate := Mid({ReportField.PatStartDate},3,2) &
Mid({ReportField.PatStartDate},6,2) &
Mid({ReportField.PatStartDate},9,2);
StringVar PatEndDate := Mid({ReportField.PatEndDate},3,2) &
Mid({ReportField.PatStartDate},6,2) &
Mid({ReportField.PatStartDate},9,2);

//Build the array of the days in the start/end parameters...
For D := 1 to NumberDays Do
(

ArrayDay := Left(EachDay[D],6);
PatCountN := CDbl(Mid(EachDay[D],9,10));
if ArrayDay GT= PatStartDate and ArrayDay LT= PatEndDate then
(PatCountN := PatCountN + 1;
Mid(EachDay[D],9,10) = CStr(PatCountN,0,""));
)



Then when I print the array by placing it in my report footer, the formula is:
Shared StringVar Array EachDay;
Join (EachDay, ChrW(13))

and it prints the YYMMDD #0 for each day that was loaded into the array and that is it.

I hope all this made sense.