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.
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.
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.
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.
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).
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).
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).
11 .Scroll down to the Fields category in the step list on the left, then double-click Set Field (Figure 5.32).
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.
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).
16 .In the list of Get functions, scroll down to Get(PageNumber) and double-click it (Figure 5.35). Click OK to return to the Edit Script dialog box.
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.
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).
20 .Type a space, then of and another space. Choose Insert > Merge Field (Control+Alt+M/Command+Option+M; Figure 5.38).
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).
When you run this script, youll see the current page number and the total page count on each page in Preview mode (Figure 5.40).
Its 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."