Using virtual tables to loop through data
Just as you can repeat code using a loop, you can also repeat data items in a report using a virtual table. This recipe will show you how to use the most common virtual table, Integer.
How to do it...
Create a new report by following the Using the Report Generation Wizard recipe.
Add the following global variable:
Name
Type
NoOfCopies
Integer
Add a label and textbox control to the request form.
Set the following property on the textbox control:
Property
Value
SourceExpr
NoOfCopies
Set the following property on the label control:
Property
Value
Caption
No. of Copies
Insert an Integer data item above the Customer data item.
Change the Name field for the Integer data item to CopyLoop.
Indent the Customer data item by using the right arrow button on the bottom of the form.
Delete the CopyLoop Body section from the Section Designer.
Add the following code to the
OnPreDataItem
trigger for CopyLoop:SETRANGE(Number, 0, NoOfCopies);
Save and close...