-1

My report Groups by two fields, the second being a date field.

If I go to 'Group Expert', select the second field (the date field), and click Options, I get the 'Change Group Options' dialog. There are two tabs (Common and Options), on the Common tab we now see three comboboxes.

Combobox1: The Date field

Combobox2: in ascending order.

And the third comobox, which exists because this is a date field, has this label above it: "The section will be printed:"

And its value is:

Combobox3: for each day.

OK. In my Formula Editor, I need to sum a field (within our group by field), so my formula looks like this:

Sum({Table.Field}, {Table.OurDateFieldWeAreGroupingOn}, "daily")

Daily is there because Group Expert is "for each day". If I change ComboBox3 to "for each month", the string in the Sum function would have to change to "monthly". The Sum function is there so that I have a running total every time crystal reports breaks on my grouping.

The issue I am running into is the string condition. This is because I want to be able to change the grouping at runtime.

For example,

switch (grouping)
{
    case Minute:
        m_Rpt.DataDefinition.Groups[1].GroupOptions.Condition = 9;
        break;
    case Hour:
        m_Rpt.DataDefinition.Groups[1].GroupOptions.Condition = 10;
        break;
    case Day:
        m_Rpt.DataDefinition.Groups[1].GroupOptions.Condition = 0;
        break;
    case Week:
        m_Rpt.DataDefinition.Groups[1].GroupOptions.Condition = 1;
        break;
    // etc, etc, etc
}

So, they allow me to change the grouping at runtime, no problem. At design-time I had "daily", but I could make it "monthly" (for example). Btw, does anybody know if I can replace the 9, 10, 0, 1, etc. with some Crystal Reports defines (something from an enum or something)? I only figured out that "weekly was 1" (for example) because that was the 2nd item in "combobox3".

Being that I can change this at runtime? How the heck can I modify the condition of my formula?

If I changed it, at runtime, to weekly, I'd need my Sum to look like this:

Sum({Table.Field}, {Table.OurDateFieldWeAreGroupingOn}, "weekly")

The problem is that in the field editor, if I use anything other than a string, I get this error: "A group condition must be a string". I had tried to pass that string as a value (for example):

Sum({Table.Field}, {Table.OurDateFieldWeAreGroupingOn}, {@ValuePassedIn})

I mean, if they allow you to change the grouping at runtime, I have to be able to change the conditions of the formulas too, right?

1 Answer 1

-1

I'm basically learning Crystal Reports on the fly, so some things might escape me at the moment ... that being said:

The Sum field was originally used because I needed to maintain a "running total" every time that the page breaks on my grouping. Well, I went ahead and crated a "Running Total" field (which doesn't require me to specify daily or weekly or monthly). Then, in my formula, I used this new Running Total field instead of the Sum function (they both did the same thing).

Problem solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.