Language:


Using Variables and Formulae - An Alternative Method for Counting Records

In the previous examples, we described using variables to count the number of records (i.e the number of Customers and the number of Invoices) in the report. You can also do this using the [Total] button on the 'Layout' card. The advantage of using Totals is that it is easier to implement: you don't need to use the [Code] button to increment the variable. In fact, you don't need to use the 'Data' card at all. The disadvantage is that there are restrictions on where in the report the figure can appear (it can only appear in a section related to the register whose records are being counted).

To use Totals to count the number of records, follow these steps:

  1. Change to the 'Layout' card.

  2. Click on the section where the Total is to appear. If you need to count the number of Customers, this will probably be the Contact Footer section. If you need to count the number of Invoices, this will probably be the Invoice Footer section. You cannot place either Total in the Report Footer: the Report Footer is not related to a register, so it cannot contain totals calculated using this method. You have to use variables as previously described.

  3. Click the [Total] button. When the 'Total' dialogue box opens, do not specify a Field. Instead, enter "1" as the Field:

    By specifying "1" as the Field, you are instructing the Total to count the printed records in the relevant register. For example, the Contact Footer section is connected to the Contact register so, if you place the Total in this section, it will count the number of printed Contacts (i.e., in the example report, the number of Customers). If you place the Total in the Invoice Footer, it will count the number of printed Invoices.

    Remember that the Invoice Footer section is printed once for each Customer. So, you can use the Clear On Print box as previously described: check this box if you do not want the total to be cumulative (i.e. if you want to print a total number of Invoices for each Customer). If you do not check this box, the count will accumulate so that when the Invoice Footer is printed for the last time it will contain the total number of Invoices in the report (i.e. for all Customers).

  4. As mentioned at the beginning of this section, there are restrictions on where in the report the figure can appear (it can only appear in a section related to the register whose records are being counted). If you want to use the figure elsewhere (e.g. in the Report Footer), specify an integer variable in the Variable Name field in the 'Total' dialogue box. You must have declared the integer variable on the 'Data' card. Then, place the variable in the report as normal using the [Formula] button.
Please click the links below for more details about: