Question:
I am outputting a report that contains more fields than will fit on a single sheet. The process has to be done as three separate reports:
- Report 1 – Fields 2 to 14
- Report 2 – Fields 15 to 27
- Report 3 – Fields 28 to 40
How can I put variables into the report fields to point to the relevant table fields? This would enable me to use one report and vary the field reference. I hope this makes sense.
Answer:
This can be accomplished using the EVAL() and FIELD() functions in combination with a memory variable that holds the field number of the first column in the report. Here is a simple example that will demonstrate the solution.
Let’s say that you have a table with seven fields in it (f1, f2…, f7). Let’s also say that the report that you create can only show three columns.
First create a report, add the table to the data environment of the report, and then put three fields onto the report designer surface. Fill in the expressions and the “Print When”s as follows:
Field Expression Print When----- ---------- -----------First EVAL(FIELD(lnStartField)) !EMPTY(FIELD(lnStartField))Second EVAL(FIELD(lnStartField+1)) !EMPTY(FIELD(lnStartField+1))Third EVAL(FIELD(lnStartField+2)) !EMPTY(FIELD(lnStartField+2))lnStartField = 1REPORT FORM MyREPORT && shows fields 1-3lnStartField = 4REPORT FORM MyREPORT && shows fields 4-6lnStartField = 7REPORT FORM MyREPORT && shows only field 7
You can use the same technique to make sure that the column headers in the report give the correct field name above its value. Create three fields (not labels) in the page header of the report, corresponding to (and right above) the three fields you first added. Set their expressions and “Print When”s as follows:
Field Expression Print When----- ---------- -----------First FIELD(lnStartField) !EMPTY(FIELD(lnStartField))Second FIELD(lnStartField+1) !EMPTY(FIELD(lnStartField+1))Third FIELD(lnStartField+2) !EMPTY(FIELD(lnStartField+2))
Notice that the EVAL() function is not used because we want the name of the field, not the contents of the field.