2 Replies Latest reply on May 9, 2015 9:58 AM by Fred_3

    IF Statement In Form Letter



      IF Statement In Form Letter


      Is there a way to place an IF statement in a form letter?  I would like to display a certain body of text if one condition exists, and a different body if a different condition.

      If this is not possible, any suggestions?  I tried a script to open the form letter and using an IF statement to set a variable, but I am only able to pass the contents of the first record.


        • 1. Re: IF Statement In Form Letter

          The If Function can be part of a calculation field that references a global variable or global field. It can return one block of text or another and you can insert it into your layout as a merge field to "flow" it into a larger body of layout text if needed. Or this can be a field from a related table where the value in a field (can be a global field so that you can make one selection for an entire set of records) and this field then is a match field to a table of related records. Put value 1 into the field and the text from a field in one record is available to include in your form letter. Put value 2 into the field and a different record's text is accessible. You'd then insert the field from the related table into your layout as a merge field like you would the calculation field. Note how this second option is very flexible as you can set up any number of alternate passages as a data entry task without having to redefine a field.

          And you might find the method demonstrated in this demo file of interest as it shows a way to construct such a "form letter" while in browse mode by typing text into a text field while inserting "placeholders" for different fields in your database. A calculation field then replaces the placeholder text with corresponding field values to produce the actual text that you'd use in hard copy, the body of an email or in a PDF.


          This file is still in the older file format so FMP 12 and newer users will need to use Open from FileMaker's File menu to open this file and thus create a copy converted to the newer file format.

          • 2. Re: IF Statement In Form Letter

            Thank you for the response.  I like where you are going with the global variable.  With that I can execute a script to open the form letter as follows:

            If [Residential Customers::Lease Rent House = "X"]

                Set Variable [$$Address1; Lessor::Street Address]

                Set Variable [$$Address2; Lessor::City & ", " & Lessor::State & " " & Lessor::Zip]


                Set Variable [$$Address1; Residential Customers::Street Address]

                Set Variable [$$Address2; Residential Customers::City & ", " & Residential Customers::State & " " & Residential Customers::Zip]

            End If

            New Window [Name: "Letters"]

            Go To Layout ["Letter" (Residential Customers)]

            The problem with this script is that it only works for the first record - or perhaps more accurately, the global variable only updates for the first record.  Which is why I thought an If statement directly in the form letter would be easier, but I guess that is not possible.  What can I do to get the global variable to change for each record?