Printing Forms with Detail Blocks Summary: Using a form to print detail records can be useful for printing invoices or lists in a highly formatted manner. It is also convenient because you can use the same form for entering data and printing. In order to print a form with a detail block which has more detail records than the number of detail rows, a little bit of programming is required. This technote explains how to print a form with many detail records without the detail records repeating and with the last page of the detail records having blank rows if the number of detail records remaining is less than the number of detail rows on the form. This technote uses the example files and form from the \SAMPLES\PERSONNL directory to illustrate the program. Open the form SITE.SBF by choosing File|Open|Form|Report. This form has fields from 2 files: SITE and EMPLOYEE. It lists all the employees for a given site. You can print the SITE file with its employee information using this form. Do this by attaching a command button with the following command behind it: RUN "PRINTROUTINE" To learn more about how to place a command button on the form, refer to the Defining Forms and Custom Reports manual. Open the program editor by choosing Program|Edit and type the following code (there a number of REM statements throughout the code for clarity, you don't need to type the lines starting with REM). REM This is the main procedure SUB main() REM Select the first record on the SITE file and display it SELECT FORM FIRST FORM REM Repeat the same for all the records in the SITE file until you encounter an End-Of -File WHILE NOT EOF ("SITE") REM Call procedure fprint CALL fprint() SELECT FORM NEXT WEND END SUB END REM This is the fprint procedure SUB fprint() i% = 1 flag$ = "True" REM Store the contents of the SITE information in a temporary variable. temp1$ = SITENO.SITE REM Switch to the Detail or EMPLOYEE file and select the corresponding records FILE "EMPLOYEE" INDEX "EMPLOYEENO" SELECT WHERE SITENO.EMPLOYEE = temp1$ SELECT FIRST WHILE NOT EOF ("EMPLOYEE") REM If there are any corresponding employee's for the site then set the flag% variable to 10. flag$="False" REM Update the rows with information from EMPLOYEE file. FOR i% = 1 TO 3 IF NOT EOF ("") THEN UPDATE FORM ROW i% SELECT NEXT ELSE REM If the number of records is less than the number of rows, blank the rows BLANK FILE "employee" UPDATE FORM ROW i% END IF NEXT i% FORM PRINT CURRENT PAGE WEND REM If there are no Detail records then print just the Site information IF flag$="True" THEN FORM PRINT CURRENT PAGE END IF SELECT WHERE FILE "SITE" END SUB Note: When using this program with different files, replace field and file names appropriately. Program: Superbase Versions: 2.0 Date: June 18, 1993 D Date: