Opening a Filtered Browse on another Form

Description

Button4 on the Detail tab of the Inventory form opens the Review of Sales form to display the sales history for the currently selected product. The procedure to create a similar button is very simple.

Procedure: Use Xbasic Code to Open Another Form Containing a Filtered Browse 

  1. Sketch a button onto the form.

  2. Enter the button's label.

  3. In the Define Button dialog box select Use Xbasic Editor and click the Next > button.

  4. Paste the code below into the Xbasic Editor and click the Finish button.

Xbasic Code Run by the Button4 OnPush Event 

dim p as P
p = Form.load("Review of Sales")
p:tables:PRODUCT.filter_expression = "PRODUCT_ID = '" + PRODUCT_ID.TEXT + "' "
p:tables:PRODUCT.query()
p.show()
p.activate()

An Explanation of the Code 

The first line creates a pointer variable named p to refer to the Review of Sales form.

dim p as P

Load the Review of Sales form. Return a pointer to the form as it is loaded.

p = Form.load("Review of Sales")

Specify the filter_expression for the form. Assuming that the product_id value was A000, the following expression would evaluate to PRODUCT_ID = 'A000'.

p:tables:PRODUCT.filter_expression = "PRODUCT_ID = '" + PRODUCT_ID.TEXT + "'"

Select the appropriate records from the Product table by using the query() function.

p:tables:PRODUCT.query()

Make the form visible.

p.show()

Make the cursor visible.

p.activate()

Procedure: Use Action Scripting to Open Another Form Containing a Filtered Browse 

  1. Sketch a button onto the form.

  2. Enter the button's label.

  3. In the Define Button dialog box click Launch Script Editor.

  4. Click Add New Action.

  5. Select "Form/Browse" from the Category list.

  6. Select "Open Form or Browse Layout" from the Action list and click OK.

    images/AL_form_inventory_action_script_1.gif
  7. Select "Review of Sales" from the Layout Name list and click Next >.

    images/AL_form_inventory_action_script_2.gif
  8. Select "Records that match the value in a Control on the current Form" from the Specify record selection criteria list.

  9. In the Show records list select the "Product_id" field from the list of the Review of Sales table's fields.

  10. In the matches the value list select the "Product_id" field from the list of the Inventory form's fields.

  11. Click Finish > Finish to return to the Form Editor.

  12. Click the 'Save' icon to save your changes.

    images/AL_form_inventory_action_script_3.gif

See Also