Put a Button on a Form to Open Another Form Showing Selected Records

Description

This example shows how you can put a button on a form that will open another form and show a selected record. Your database should contain a form called "CustomerFormCompact," which shows the customer's address (as shown below) in a rich text object. This object is not editable. So you cannot change the customer's address on this form. You will put a button on the form to open another form (called "CustomerEdit," which has been pre-created for you) where you can edit the address.

  1. Navigate to the Forms tab on the Control Panel and open "CustomerFormCompact".

  2. Click the Design button to enter Design Mode.

  3. Click the Button Object tool on the Toolbox. Click and drag to draw a button on the form. When you release the mouse button, the Define Button dialog box appears.

  4. Select "Picture over Text" as theStyle.

  5. Enter "Edit Customer" as theLabel.

  6. Click the Define Picture button.

  7. Click the Internal radio button and then click the up arrow.

  8. In the resulting Insert Image dialog box select the image you want for your button. Choose any image you find appropriate.

  9. Click Insert to close the dialog box.

  10. The Define Button dialog should look like this:

  11. Make sure that the Define script for this button now? check box is checked and that Use Action Scripting is selected.

  12. Click Next >. The embedded Action Scripting Editor appears.

  13. Click the Add New Action button.

  14. Select the "Form/Browse" category and the "Open Form or Browse Layout" Action.

  15. Click OK.

  16. The Open Form or Browse Layout Genie appears.

  17. Select the "CustomerEdit" form.

  18. Click the Options tab. This screen allows you to set options, such as whether the form is to be opened as a normal (modeless) window, or a modal dialog box.   

  19. The user should complete any edits before closing the  CustomerEdit form. For Window Style, select "Dialog (form opens as a modal window)".

  20. Click Next > to move to the next Genie page. The next page allows you to select which records will be shown when  CustomerEdit is opened. You want to show the same record that you were viewing in the current form.

  21. Select "Records that match the value in a Control on the current Form". The current form has a control (a field) that shows the "Customer id" field. You want to open the  CustomerEdit form showing the same record.

  22. Complete the Filter tab as shown above.

  23. Click Next > and Finish to complete the action. The embedded Action Script Editor looks like this:

  24. Finish to close the Define Button dialog box and close the Action Script Editor.

  25. Click the Save button to save the form.

  26. Click the Form View button to run the form. Your screen should look like this:   

  27. Click the Edit Customer button.

  28. The CustomerEdit form opens. Note that it's modal. You cannot click on any other part of the Alpha Anywhere screen.

  29. Make changes to an address value, then click the Close Form button.

  30. The dialog form closes and returns to the "CustomerFormCompact" form. Your edits should be visible in the form.

  31. In case you're curious about how the Close Form button on the CustomerEdit form was constructed, let's take a look at the script behind the "Close Form" button.

  32. Click the Forms tab on the Control Panel and select the CustomerEdit form.

  33. Click the Design button.

  34. Right-click the Close Form button and select Events > OnPush.

  35. When the Code Editor appears, >Close Form/Browse Action and Edit Action.

  36. As you see in the Genie, the action closes the current form window, and automatically saves the record that the user is editing in the form.