asked on # How do I programatically change the Crystal reports formula for a Groupfooters "New Page After" property?

I want the user to be able to select a checkbox if they want a page break after each group of information. The following code works fine if I don't have a formula in the "New Page After" formula. But as soon as I put "formula = Not OnLastRecord" in at design time setting the property to true or false has no effect. It always puts in a page break.

If cboxPageBreak.Checked Then

objReport.GroupFooterSection2.SectionFormat.EnableNewPageAfter = True

Else

objReport.GroupFooterSection2.SectionFormat.EnableNewPageAfter = True

End If

How can access the formula section of "NewPageAfter" to remove the formula at run time?

If cboxPageBreak.Checked Then

objReport.GroupFooterSecti

Else

objReport.GroupFooterSecti

End If

How can access the formula section of "NewPageAfter" to remove the formula at run time?

.NET ProgrammingVisual Basic.NETCrystal Reports

I have the report document object and I'm able to program the "RecordSelectionFormula" and I'm also able to access the boolean value of "EnableNewPageAfter" as in my example:

objReport.GroupFooterSection2.SectionFormat.EnableNewPageAfter = True

But there is a place in design mode for setting a formula associated with "NewPageAfter" that allows you to control things like suppressing the page break on the last page, etc. I can't figure out how to access this formula at runtime. Do you have any example of code for this property?

objReport.GroupFooterSecti

But there is a place in design mode for setting a formula associated with "NewPageAfter" that allows you to control things like suppressing the page break on the last page, etc. I can't figure out how to access this formula at runtime. Do you have any example of code for this property?

When you use the formula it overrides the check mark in the selection.

When do you want a new page after?

Are you trying to prevvent a blank last page?

mlmcc

When do you want a new page after?

Are you trying to prevvent a blank last page?

mlmcc

I don't believve you can access those formula at runtime. You could use a formula in the NEW PAGE AFTER formula and then control that formula through code.

mlmcc

mlmcc

I have the formula "formula = Not OnLastRecord" in the NEW PAGE AFTER formula, so how do I control that formula through code? If I can't access those formulas at runtime how do I control it? What am I missing?

As I stated you can't.

What are you trying to accomplish with the NEW PAGE AFTER formula?

mlmcc

What are you trying to accomplish with the NEW PAGE AFTER formula?

mlmcc

I want to provide the user the option of inserting page breaks after each group or not. So I give them a checkbox control to enable or disable page breaks.

By the way, is it just a typo that you have the "=true" in both parts of the if condition?

Yes. This was a typo. Thanks for pointing it out. However my code is correct.

Do you know how to pass a parameter to the report?

If so

Add a parameter to teh report (boolean)

In the formula for New Page After

{?NewPageAfterParameter} = True

mlmcc

If so

Add a parameter to teh report (boolean)

In the formula for New Page After

{?NewPageAfterParameter} = True

mlmcc

To avoid the new page after the last record

In the formula for New Page After

{?NewPageAfterParameter} = True

AND

Not OnLastRecord

mlmcc

In the formula for New Page After

{?NewPageAfterParameter} = True

AND

Not OnLastRecord

mlmcc

I may be wrong, but it seems like you missed part of what mlmcc was saying, so, putting on my interpreter's hat:

I don't run CR reports from code, but I think what mlmcc was saying was that you can't change the "New Page After" formula through code, but what you can do is create a separate formula, use that formula in the "New Page After" formula, and then alter the separate formula through code.

For example, create a formula named @newpage that just says "formula = True", or maybe "formula = not OnLastRecord". Whatever. Then your "New Page After" formula would just be "formula = {@newpage}". If you alter the @newpage formula using code, that will determine whether or not "New Page After" is true.

James

I don't run CR reports from code, but I think what mlmcc was saying was that you can't change the "New Page After" formula through code, but what you can do is create a separate formula, use that formula in the "New Page After" formula, and then alter the separate formula through code.

For example, create a formula named @newpage that just says "formula = True", or maybe "formula = not OnLastRecord". Whatever. Then your "New Page After" formula would just be "formula = {@newpage}". If you alter the @newpage formula using code, that will determine whether or not "New Page After" is true.

James

James,

Thanks for that clarification, unfortunately I can't seem to get anywhere with this approach. If I create a formula @newpage that says just "formula = not OnLastRecord" and then put "formula = {@newpage}" this would translate to "formula = formula = not onLastRecord". So if I modify either formula to eliminate one "formula =" Crystal Reports doesn't like the formula. It allows me to save it anyways, but when I execute my code the CR viewer gets upset before my code even has a chance to modify the formula. Not sure how to work around that. Any ideas? I'm going to try to use parameters as mlmcc has suggested in the previous post.

Thanks for that clarification, unfortunately I can't seem to get anywhere with this approach. If I create a formula @newpage that says just "formula = not OnLastRecord" and then put "formula = {@newpage}" this would translate to "formula = formula = not onLastRecord". So if I modify either formula to eliminate one "formula =" Crystal Reports doesn't like the formula. It allows me to save it anyways, but when I execute my code the CR viewer gets upset before my code even has a chance to modify the formula. Not sure how to work around that. Any ideas? I'm going to try to use parameters as mlmcc has suggested in the previous post.

View this solution by signing up for a free trial.

Members can start a 7-Day free trial and enjoy unlimited access to the platform.

View this solution by signing up for a free trial.

Members can start a 7-Day free trial and enjoy unlimited access to the platform.

Like this

private void SetDatabaseLogon(ref ReportDocument _pReportDocument)

{

try

{

//if (_ReportDocument.Name.Cont

//{

// _ReportDocument.RecordSele

//}

//if (_ReportDocument.Name.Cont

//{

// _ReportDocument.RecordSele

//}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message

}

}