"SBase Personal - 25. MAIL MERGE" 25 MAIL MERGE Preparing for Mail Merge Creating a Form Letter Inserting Date and/or Time Using the & Character in the Text Fixed Length Fields Running Mail Merge Setting the Mail Merge Filter Previewing Mail Merge Blank Lines Mail Merge Applications Mail Merge with Multiple Files Programming Mail Merge 25 MAIL MERGE With the Mail Merge command you can generate a large number of personalized letters from a single Text Editor document. Each letter will be based on the same `form' letter that you have created in the Text Editor, but the names and addresses will be inserted from a SBase 4 file which holds a mailing list. Preparing for Mail Merge Two things are required before you can print out letters with Mail Merge. First, you need a file containing the names and addresses of all the people who are to receive a letter - the targets of your mailing. Second, you need to create the form letter which will be merged with these names and addresses. Creating a Form Letter You create a form letter using the SBase 4 Text Editor. In appearance, it will be like any other letter except instead of actual names and addresses it will contain field names. 1. Open the SBase 4 file containing names and addresses. 2. Select the Text Editor from the Utilities menu (or press AMIGA+H). 3. Type the text of the form letter in the normal way. 4. When you want to include a field name from the database file, position the cursor and then select the Merge Field command from the Edit menu. 5. SBase 4 presents the Merge Fields requester with a list of field names from the current file. Click the name of the required field. 7. Click OK. 8. SBase 4 inserts the field name, delimited by the ampersand `&', into the text. 9. Save the letter as a Text Editor document. Inserting Date and/or Time You can insert the system date or time in a document. This is done by typing the TODAY or NOW keywords delimited by ampersands directly in the text: &TODAY& Using the & Character in the Text If you need to use the ampersand character for other purposes, you should enter it in the text as a double ampersand (&&). SBase 4 recognizes a double ampersand in a text document as an intended single ampersand, so that text such as `Laurel & Hardy' does not confuse the merging process. Fixed Length Fields You may want to lay out a form letter in such a way that the contents of a field always start in the same column on the page. Normally, if a letter has two fields on the same line, the second field may be printed in a different position in each letter, depending on the contents of the first field. The fixed length command lets you set the length of the first field; or, more precisely, it lets you fix the length of the output from the first field. By doing this, you can ensure that the contents of the second field are always printed at the same position. If the contents of the first field are shorter than the specified length, SBase 4 inserts spaces (if they are longer, it truncates them). The maximum Fixed Field length is 256 characters. You set a fixed length for a field manually by typing dashes between the end of the field name and the second ampersand. The length is specified by the number of characters from the first ampersand to the second ampersand. For example: &Firstname---& &Lastname& The fixed length for the Firstname field is 14 characters - nine characters in `Firstname' plus two ampersands and three dashes. If the contents of this field are printed at column 1, the Lastname field will always be printed at column 16, no matter how long or short the first name is. Running Mail Merge Mail Merge takes data from the records specified by a filter. It starts with the first record in the current index sequence. It replaces the field names in the form letter with the data from the corresponding fields in the record. It prints the letter and then fetches the next record. This process is repeated one letter for each record until the last record has been merged with the form letter. The procedure for printing letters using Mail Merge is as follows: 1. Switch on and set up the printer. 2. Open the database file containing the data which is to be inserted in the form letter. - If you know that no text file is open, you can omit the next two steps. 3. Select Text Editor from the Utilities menu and then open the text file containing the form letter. 4. Return to the database by clicking in the database window. 5. Select Mail Merge from the Process menu. - If there is no text file open, SBase 4 presents you with a requester containing a list of text files. Click on the name of the required form letter, then on OK. 6. You will be presented with a Filter requester. Set any required filter conditions to select records for merging (see Setting the Mail Merge Filter below). 7. Click OK. Another requester will appear: *** See Fig 25-1 *** 8. Click Yes to start the Mail Merge operation. Setting the Mail Merge Filter You can use the Mail Merge filter to specify which records are to be used. If you leave the filter line blank, Mail Merge will print a letter for each record in the file. Mail Merge presents you with the standard filter requester, and you build up your filter command line in the usual way. Here are some examples of a Mail Merge filter line: Date >> "1 September 1990" AND Date << "31 August 1991" This line selects all the records where the date field falls between these two dates. Lastname LIKE "S*" This filter instructs Mail Merge to print letters for all the people in the file whose names begin with S. Previewing Mail Merge Mail Merge allows you to preview letters on screen before committing them to print. This enables you to see what the letters will look like when the names and addresses have been inserted in them. The preview option is selected at the stage when the Output to Printer requester appears. Clicking No instead of Yes causes Mail Merge to output letters to the screen. Preview displays each letter in turn, from the first letter onwards. If you set Paging on (from the Set menu), the preview pauses whenever the screen becomes full. Click the Pause button or press SPACEBAR when you want to move on to the next letter. Click the Stop button or press CTRL+C to bring the process to a halt. Otherwise, Mail Merge will preview all the letters that have been selected by the filter. If you intend to print a large number of letters, previewing all of them may take some time. Notice that letters are reformatted after the record data has been inserted. This means that the contents of a field may move the text which is on the right onto to the next line. As a result, text on the last line of the page will be moved to the start of the next page. Blank Lines One of the problems with merging a set of address fields is that in some records one of the fields may be empty. For instance, the address may not include a city name. If this line were left blank when the letter was printed, there would be an unsightly gap between the street name and the zip code. SBase 4 solves the problem by checking whether a field is empty or not. If it is empty, the field is not merged and the fields above and below are printed on consecutive lines. Mail Merge Applications Mail Merge does not restrict you to names and addresses. This is simply the most common mail merge application. Any field name may be used and it may be placed anywhere in a document. You could create a form letter which said: We would like to remind you that payment on the invoice dated &Date&, for the sum of &Amount&, is now 60 days overdue. In this case, though, the fields Amount and Date would have to be present in the same file as the name and address fields. It is possible to use field names from more than one file, provided the file name is given as well as the field name. However, when the letters are printed, SBase 4 will only select records from the current file. The current record in another file will stay the same and a field from this file will print the same data in each letter. Even so, there are some circumstances in which Mail Merger's multi-file capability can be useful. Suppose your company was sending out letters in batches, where each batch included all the customers in a particular area. By using a Dealers files you could give each customer information about the dealer in their area. The form letter would include the line: The dealer for your area is &Name.Dealers&, &Address.Dealers& To do this, you would need to select the required record from the Dealers file before printing each batch of letters. Fields may also be repeated in a letter. Mail Merge with Multiple Files The Mail Merge command works with a single file. If you require to merge data from more than one file into a document, all you have to do is create a new database file containing the joined data with the Query to SB File command. See Chapter 15 Reorganizing the Database. You may then open the new file and select Mail Merge. Alternatively, you may prefer to program the application as illustrated below. Programming Mail Merge (Only in SBase Professional 4) If your mail merge application is more complex than usual, perhaps because it involves extracting data from multiple files, you will need to construct a simple DML program to solve your problem. - You may place variables in a mail merge document. - You may use the ? TEXT MERGE command to output a merged document under program control. First, change your merge document. Place any variables you wish to use inside ampersands: &x$&. Second, write a program to assign the required data to the variable after loading the text document, and then print it: OPEN FILE "Dealers" : SELECT FIRST LOAD TEXT "LETTER1" WHILE NOT EOF ("Dealers") X$ = credit_limit.Dealers ? TEXT MERGE SELECT NEXT WEND - Include the PRINT command before the WHILE line to direct output to the printer. You must ensure that your program assigns a value to every variable before you try to merge it, or SBase 4 will display the `Variable Not Defined' error message.