Save the sum of the field in the selected row to another field with a button

i have a table. I want to make total of selected field to another field with a button.
i have a total_net field. i want to sum of all selected total_net field to another field in another form.
Thank for your help

please help me. Thanks

Hy.
There are several ways but to me the best would be to create a TotalField and an ajax button in the form.
In the button event use an sql statement to compute the sum and assign the result to TotalField.

Something like

$sql=‘select sum(TotalNet) from MyTable’;
sc_lookup(rs,$sql);
{TotalField}=$rs[0][0];

not working :sneezing_face:

i have 2 forms.
1- orders (orderno)
2- form_table (ref_no)

in form_table i did use master detail form and i did call orders form to form_table

total_net field totals must come to form_table ord_inprice field.

if({orderno} != ‘’) {

$str_sql = "SELECT SUM(total_net) AS total
            FROM orders WHERE orderno = {ref_no}";
   
sc_lookup(dataset,$str_sql);

{ord_inprice} = (!empty({dataset}[0][0]))?{dataset}[0][0]:{ord_inprice}; 

You code seems correct.
Some comments:

  1. In what event did you put this code ? I cannot see in your screenshot the button created in Form_Table to execute this code.
  2. If you enable debug what error do you get ?

Since is a master-detail, when you calculate the total:

  • Update the table master if you want to store the value in the master table
  • Refresh the field {ord_inprice} located in the master from the detail with sc_master_value(‘ord_inprice’,$total);