When you print a multipage document, you often set a page number header or footer in the applications print options. This information is particularly useful when you send a report out for duplication, and its invaluable for keeping the pages in order. FileMaker doesnt have a built-in function for the page total, so youll need a bit of scripting to provide this information. If youve never scripted before, youll find Chapter 7 useful in understanding what youre doing here.
To display a page count
1 .Choose File > Define > Database (Control+Shift+D/Command+Shift+D).2 .When the Define Database dialog box appears, click the Fields tab.3 .Type the name of your new field in the Field Name text box (well use the name gPageCount). From the Type drop-down list, select Number (Control+N/Command+N) (Figure 5.26). Click Create.
Figure 5.26. The field type must be Number to count the pages.
4 .Click Options. When the Options dialog box appears, click the Storage tab. In the Global Storage section, check the "Use global storage (one value for all records)" (Figure 5.27) check box. Click OK, then OK again.
Figure 5.27. When set to use Global Storage, the field gPageCounts value is the same in every record.
We placed a g at the beginning of the field name to help us remember later that this field uses global storage.5 .Choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S).6 .When the Define Scripts dialog box appears, click New (Figure 5.28). When the Edit Script dialog box appears, type the script name.
Figure 5.28. A new script name should be different from existing scripts, and clearly describe what the script does.
For this example, we use Set Last Page Number as the script name.7 .Double-click Go to Layout in the Navigation section of the script step list on the left (Figure 5.29).
Figure 5.29. The Go to Layout script step opens the layout you specify.
8 .From the Specify drop-down menu in the Script Step Options section at the bottom, choose the layout in which you want to display the page count (Figure 5.30).
Figure 5.30. The script must first go to the layout you want to print.
9 .In the Navigation section of the step list on the left, double-click Enter Preview Mode. In the Script Step Options section, uncheck the Pause box.You dont need a Pause after you enter Preview mode, because you wont need to check the layout before continuing.10 .In the Navigation section of the step list on the left, double-click Go to Record/ Request/Page. In Script Step Options, choose Last from the Specify drop-down menu (Figure 5.31).
Figure 5.31. The Go to Page (Last) step will go to the last page in the report.
12 .In Script Step Options, check the "Specify target field" check box.13 .When the Specify Field dialog box appears, choose the field namein our example, gPageCount (Figure 5.33). Click OK to close the box and return to the Edit Script window.
Figure 5.33. The gPageCount field will display the total number of pages.
14 .In Script Step Options, click the Calculated result Specify button.15 .When the Specify Calculation dialog box appears, click the View drop-down menu and scroll down to choose "Get functions" (Figure 5.34).
Figure 5.34. Get functions are only available when that option is chosen in the View drop-down menu.
This Set Field step replaces whatever is in the global number field (in our example, gPageCount) with the page number FileMaker finds.17 .In the script step list on the left, double-click Go to Record/Request/Page again, and leave it set to First (Figure 5.36). Click OK and then OK to finish.
Figure 5.36. The Go to Record/Request/Page (First) step returns to the first page so you can see the report from the beginning.
Next we add the number field and accompanying text to a layout.18 .Switch to the layout you chose in step 8. Choose View > Layout Mode (Control+L/Command+L). In the status area on the left, click the Text tool, then click in the Header part of the layout.19 .Type Page and a space. Choose Insert > Page Number Symbol (Figure 5.37).
Figure 5.37. The Page Number Symbol will be replaced with the current page number.
20 .Type a space, then of and another space. Choose Insert > Merge Field (Control+Alt+M/Command+Option+M; Figure 5.38).
Figure 5.38. The Insert > Merge Field puts a field in a string of text on the layout.
21 .When the Specify Field dialog box appears, scroll down to your number field (ours is gPageCount) and double-click to insert it in the layout (Figure 5.39).
Figure 5.39. The field gPageCount will display the total number of pages on each printed page.
TipIts always a good idea to put the field type somewhere in the name of a summary field, so you can easily recognize its purpose. For example, "Sales Totals Summary" is more useful for database planning than "Sales Group 1."