DOCUMENT #771 =========================================================================== PRINTING FROM AN EEP =========================================================================== PRODUCT: R:BASE VERSION: 4.5+ or Higher =========================================================================== CATALOG: Forms, Reports & Labels AREA : Forms =========================================================================== Printing the data just entered is another action that has been made easier to do with 4.5 Plus!. You can automatically print as soon as a row is saved, you can prompt the user, you can add a print "button" to your form. All are easily done. Here we show the techniques used to do this. They can be easily adapted and added to your applications. Automatic printing This is the easiest. To print every row as it is entered, place the EEP at the table level After saving row. The row is saved and then the report printed. Your EEP only requires commands to set the output and to print the report. You must have a form expression, however, that places the rows identifying number into a variable, vtransid = transid. That lets you print just that row. For example, *( PRINT.EEP) OUTPUT PRINTER PRINT invoice WHERE transid = .vtransid OUTPUT SCREEN RETURN You can add error checking code, code to let the user select the output device, etc. Automatic printing from a region In a form with a region as the last table, however, you can't place the EEP After saving row. In a region, each row is saved as you leave it and move to the next row. The printing EEP needs to execute only after all the rows have been added to the region. Place the EEP On exit from a row and check for keystrokes. The EEP prints the report if the user presses Alt-A to go to the menu. *(PRINT.EEP) IF (LASTKEY(0)) = '[Alt]A' THEN SAVEROW OUTPUT PRINTER PRINT invoice WHERE transid = .vtransid OUTPUT SCREEN ENDIF RETURN The EEP only command, SAVEROW, is needed here because the EEP executes before the last row has been saved to the table. The EEP is On exit from a row and executes before the menu selection is executed. Conditional printing The previous two techniques automatically print the report. There is no user interaction or intervention. The report prints based on certain actions taken in the form. You can make the EEP more generic by adding a simple dialog box. This gives you more options as to placement of the EEP and when it executes. Prompt to print the report if the user goes to any menu option. The EEP stays placed On exit from a row. *(PRINT.EEP) IF (LASTKEY(0)) IN ('[Alt]A', '[Alt]G', '[Esc]') THEN DIALOG 'Print invoice? ' vresp, vkey YES IF vresp = 'YES' THEN SAVEROW OUTPUT PRINTER PRINT invoice WHERE transid = .vtransid OUTPUT SCREEN ENDIF ENDIF RETURN Remember, the EEP code is executing before the menu action takes place. Using a print "button" The above techniques are designed for adding new data to a form. When editing data, you may want to add a print "button" to your form. A print "button" is a located variable that prints a report when the user moves to that field. It uses a field level EEP rather than a table level EEP. This technique can also be used on an entry form with the SAVEROW command. Use the new mouse position functions to print if the user moves to the field with keys or with the mouse. To add a print "button" to a form whose last table is a region, you use a dummy table. This lets you locate a variable field, your print "button", after the region. The variable has an EEP On exit from field that prints the report. The dummy table is added as the last table in your form. It doesn't need any fields in common with other tables in the form. Load the dummy table with one row of data. CREATE TABLE dummy_tab (dummy_col INTEGER) LOAD dummy_tab L> 1 L> end With the dummy table the current table in the form, locate a TEXT variable, vyesno, one character wide. Add text such as, Print report?, to the left of the variable location. Customize the field settings to make the variable editable, add an EEP On exit from field. Next, add expressions to your form. You must have a form expression that places the row's identifying number into a variable, vtransid = transid. In addition, add an expression to the dummy table to put a default value into the print "button" variable, vyesno TEXT = 'Y'. The EEP checks the value of the vyesno variable. If 'Y', the default, it prints the report. *(PRINT.EEP) SET MESS OFF SET ERR MESS OFF IF .vyesno <> 'Y' AND .vyesno <> 'N' THEN SKIP 0 RETURN ELSE IF .vyesno = 'Y' THEN OUTPUT Printer PRINT invoice WHERE transid = .vtransid OUTPUT SCREEN ENDIF ENDIF RETURN The EEP has error checking to ensure that only a 'Y' or an 'N' is allowed to be input into the variable. If any other character is entered, the SKIP 0 command prevents the cursor from advancing out of the field. Read the articles on windowed forms, conditional EEPs and action EEPs for more ideas on adding a custom print "button" to your form.