Skip to main content Skip to footer

Different Number of Records in C1ReportDesigner

Report Generation is one of the most important parts of an enterprise application. The report definition files can be created using C1ReportDesigner application. It is common to want to display different numbers of records on individual pages in a C1Report. There is a property "RecordsPerPage", with which we can specify the number of records revealed per page, but this would mean that all the pages show the same number of records. Through this article we will discuss an alternative method that can be used to specify different numbers of records on individual pages in C1Report. **Please note that this approach is not a generic one and you will need to specify the number of records for each page.**

Step 1 : Create a ReportDefinition XML File

Let's start by creating a ReportDefinition file. 1. Open the C1ReportDesigner 2. Click on newreport option. 3. A dialog with the title 'Select the datasource for the new report' will pop-up. 4. Select the provider and connection, then browse to the location where the datatable is stored. 5. Add the desired fields and create the report. Now we have a report working report definition file. Click on the Preview button of the C1ReportDesigner.

Step 2 : Specifying Record Number Per Page

Place a counter Field in the Detail section of the report. Set its Text empty and Visible property to False. We will call this Field1. This is the field that plays the most important role in achieving our goal as the page break will be implemented using this field. Open the Report Properties in Property grid and Click on OnOpen property and write cnt = 0 in the VbScript editor. Next, click on the Detail section to view its properties in the Property grid. click on the OnFormat property to open the VbScript editor. In our code we will specify that after every 10 records we will add a PageBreak and render the rest of the records on the next page. Every time the pagebreak is added, the counter is reset to zero and again its value is incremented up to 10. Code

cnt = cnt  1  
If cnt <10 then  
Field1.ForcePageBreak=false  
end if  
if cnt  mod 10 = 0 then  
Field1.ForcePageBreak=True  
cnt =0  
end if

This is similar to setting RecordsPerPage property. The real task is in specifying which page will show the desired number of records. In our example, we will display 5 records on Page1 and 7 records on Page3. Code



If Page="1" and cnt ="5" then  
Field1.ForcePageBreak=True  
cnt =0  
end if  

If Page="3" and cnt ="7" then  
Field1.ForcePageBreak=True  
cnt =0  
end if

Hence, our entire code snippet should mirror the following : 

cnt = cnt 1
If cnt<10 then
Field1.ForcePageBreak=false
end if
if cnt mod 10 = 0 then
Field1.ForcePageBreak=True
cnt =0
end if

If Page="1" and cnt ="5" then
Field1.ForcePageBreak=True
cnt=0
end if

If Page="3" and cnt ="7" then
Field1.ForcePageBreak=True
cnt =0
end if

 The Report would like the following image, which shows a different number of records in page 1 and 2: ![](//cdn.mescius.io/assets/developer/blogs/legacy/c1/2011/5/8836.preview.png) Attached is a sample report definition file. All you need to do is change the connection string to the C1Nwind.mdb database in the ComponentOne Sample\\Common folder of your machine to see the demo of the implementation explained above. [Download Sample](//cdn.mescius.io/assets/developer/blogs/legacy/c1/2011/05/ReportDefinitionFile.zip)

MESCIUS inc.

comments powered by Disqus