Three or four buttons are efficient, but as you add more buttons your layout will start to look (and feel) cluttered and cramped. You'll be back where you started, having to negotiate too many chaotic choices. Although you could make a Main Menu page, not all databases lend themselves to this solution. If you have a database with many reports, for example, you will be better off if you create a script that offers one field with a drop-down list of choices.Before you can create this script, you'll need a field set with a global storage option and formatted as a drop-down list, and a list of scripts you want to use for the value list. You'll also want to be sure that "Add newly defined fields to current layout" is checked in the Edit > Preferences / FileMaker Pro > Preferences Layout tab.
To make a formatted global field
1 .Go to the layout that will contain the formatted list. Choose File > Define > Database (Control+Shift+D/ Command+Shift+D). Click the Fields tab.2 .Type a name for the field (we use gReports). Choose Text (Control+T/Command+T) for the field type (Figure 9.33). Click Create.
Figure 9.33. The gReports field will contain text.
3 .Click the Options button. When the Options dialog box appears, click the Storage tab. Under Global Storage, check the "Use global storage" check box (Figure 9.34). Click OK.
Figure 9.34. gReports is a global field, so its contents are the same in every record.
This field will automatically be added to your layout. Next we'll create a value list of script names to display in the field.4 .Choose View > Layout Mode (Control+L/Command+L).5 .Drag the Field tool into the layout. Choose gReports in the Specify Field dialog box (Figure 9.35). Click the gReports field and choose Format > Field Format (Control+Alt+F/Command+Option+F).
Figure 9.35. Specify gReports when you add the field to the layout.
6 .When the Field Format dialog box appears, choose Pop-up List in the "Format field as" section. From the "Display values from" drop-down menu, choose Define Value Lists (Figure 9.36).
Figure 9.36. The gReports field will use a value list to display the choices.
7 .When the Define Value Lists dialog box appears, click New (Figure 9.37).
Figure 9.37. You'll create a new value list for the names of the scripts.
8 .When the Edit Value List dialog box appears, give the value list the same name as you gave the global field (we use gReports).9 .Click inside the "Use custom values" box and type the names of the scripts that you want to choose from (Figure 9.38). Click OK three times to finish.
Figure 9.38. Enter the script names for the drop-down value list.
You now have the global field placed in a layout, with all of the choices listed in a drop-down menu. All you need now is the script to run these choices for you.
To make a script to run scripts
1 .Choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S). In the Define Scripts dialog box, click New. In the Edit Script dialog box, type a name for the script. (We use Choose Report.)2 .In the step list on the left, double-click Go to Field. Under Script Step Options, click Specify.3 .When the Specify Field dialog box appears, select gReports. Click OK (Figure 9.39).
Figure 9.39. Add the gReports field to the layout.
4 .In the step list on the left, double-click Pause/Resume Script.This step makes the script wait while you select a report from the drop- down menu.5 .In the step list on the left, double-click If. Under Script Step Options, click Specify.6 .In the field list on the left in the Specify Calculation dialog box, double-click gReports.7 .Double-click the = operator, then click the quotes. Within the quotes, type the name of the first report you added to the value list in your global fieldours was Annual Report (Figure 9.40). Click OK to close the dialog box.
Figure 9.40. The If step will run the script you choose. Specify the first report in your value list by typing it within the formula quotes.
8 .In the step list on the left, double-click Perform Script.9 .Click Specify in Script Step Options. In the "Specify Script" Options dialog box, choose the script that matches your first report (Figure 9.41). Click OK.
Figure 9.41. Specify which script will run when you choose the report.
Our If step indicates that if you choose Annual Report from the drop-down menu, the script called Annual Report will run.10 .In the script-assembly list, click the If step, hold down the Shift key and click End If. Click Duplicate to make a second copy of the entire If sequence (Figure 9.42).
Figure 9.42. Duplicating the steps is easier than creating additional ones from scratch.
11 .Double-click the new If step to bring up the Specify Calculation dialog box.12 .Edit the report name in the formula box to match your second script (Figure 9.43). Click OK.
Figure 9.43. Change the formula for the new steps.
13 .Click the new Perform Script step.14 .Click Specify in Script Step Options and select the script that matches the report name you just typed (Figure 9.44).
Figure 9.44. Edit each If and Perform Script step. Make sure they always match each other.
15 .Repeat steps 1014 for as many reports as you want in the drop-down menu.16 .Highlight the last End If step in the script-assembly list (Figure 9.45). In the step list on the left, double-click Go to Layout. Leave "original layout" as the selected option (Figure 9.46).
Figure 9.45. A new step is added after a highlighted step.
Figure 9.46. After the script is run, this step will return you to the layout you were originally in.
17 .Click OK. If "Include in menu" is checked for this script in the Define Scripts dialog box, uncheck it (Figure 9.47). Click OK to finish.
Figure 9.47. This script will run only when you click its button, so there's no point in having it appear in the Script menu.
Now that we have a script, we need to connect it to the Reports field by making the field a button.
To make a field into a button that runs a script
1 .Click the field you want to run the script (in our example, it's the gReports field) and choose Format > Button.2 .In the scrolling list on the left of the Specify Button dialog box, click Perform Script.3 .Under Options, click Specify. In the "Specify Script" Options dialog box, select the script you just created (in our example, Choose Report, Figure 9.48). Click OK twice.
Figure 9.48. Format the field as a button that runs the Reports script.
4 .Use the Text tool to add helpful instructions to the layout (Figure 9.49).
Figure 9.49. Add instructions to the layout to clarify what the button does.
TipTo speed up the process of adding new fields to an existing layout, choose Edit > Preferences / FileMaker Pro > Preferences (Command+,). Click the Layout tab and check "Add newly defined fields to current layout" (Figure 9.50). Now you can go to the layout where you want a field, define the new field, and see it appear automatically in the layout. This can be more convenient than the manual method of defining each field, then returning to the layout, clicking the Field tool, and dragging it to define the field.
Figure 9.50. This choice automatically adds new fields to whatever layout is in use.