Create a Subform (browser)


A browser is a form that displays the table’s records or query’s result in rows and columns 
(something like a datasheet, but with read only rights).
For example, when you open the form of a customer you want to see his orders or his payments. 
Browser is a convenient tool for doing this.
A browser gets data from a query, the example below shows the steps and the code 
for a customer order-browser into the customer form with three columns, 
date, order number and amount.


1. Open the form and go to design view (right click on the form and select designing).
2.
Click “AutoScript” (in the window “Set” on the right).
3. You must write your query (you need a query that calls the specific customer’s records from the table) in the procedure Panels_Start and run it from the procedure Form_Start.
See the example below.

lib

proc
Panels_Start()
         start_sql "
ORDERS"1   "KOSMOS"
               SELECT ORDERS.DATE, ORDERS.ORDER_NUMBER, ORDERS.AMMOUNT
               FROM ORDERS
               WHERE ORDERS.CUSTOMERS = :C 2
               ORDER BY ORDERS.DATE
         end_sql

end

proc Form_Start()
    ……

    ……
    ……
    cust_id = getfprevfield("CUSTOMER" 3)
    call RunEmbSQL("ORDERS" 4, cust_id)
    q = QueryByName("ORDERS"5)
    call TPrepare(q)
    f = TopForm()
    p = PByName(f,"ORDERS"6)
    call AdjustControls(p)
    ……

    ……
    ……
end

1. In the “” you must write the query’s name (anything you want)
2. This is the query’s filter, we need the orders from the specific customer.
3. This is the value for the query’s filter (the value from the form’s field ‘CUSTOMER’)
4,5,6. Query’s name

4. Exit designing and save changes.
5. Open the form again and go to design view.

6. Click inside the form (click the frame of the form).
7. Select "Data frame (grid)" from the menu "Insert".
8. When the Data Group Wizard is open, 
     write the query’s name in the field “Query Name”, click the button “Run Query”
     select the fields that you want to include from the query and their captions, 
     and then click “create data group”.
9.  Exit designing and save changes.
10. Open the form again and go to design view.
11. Place the subform on the form wherever you want.
12. Exit designing and save changes.
For more help please see