Hello,
let’s assume I’ve a table with 4 fields:
- id primary key
- a integer
- b integer
- total integer
The total field should be a + b
If I make a form for inserting data, how can automatic insert the value of total ?
Hello,
let’s assume I’ve a table with 4 fields:
The total field should be a + b
If I make a form for inserting data, how can automatic insert the value of total ?
I think that you should explain why make this in “Base”, while this is something for “Calc”?
Maybe your question should be how to use a “Calc” form in “Base”?
Consider making a query where you can calculate field values, and by means of this query create a Form.
Hope this helps.
He, in a table of Base you can get a+b with a macro or with a SQL direct command. But with a query it is easier:
SELECT "a"+"b" AS "Total" FROM "your_table_name"
See my attach:
You may have read that you can put a formula in a column, similar to a spreadsheet. If you are using an embedded database that uses HSQLDB 1.8.10 that is not possible. If you use a split database that uses HSQL 2.3.3 then it can be done.
However it is not considered to be a good methor as the formula is only applied when a new record is created. I any of the fields used in the formula for existing records the formula will not be applied, as it would be in a spreadsheet. Also you cannot change the formula such as a situation where you were using retirement age which is changing in most countries.
As @BlueBike stated this is best suited to a spreadsheet. Or you can use a Query
SELECT “ID”, “a”, “b”, “a” + “b” “Total” FROM “TableName”
to have the Total but not saved to the Table
If you need to do it as you stated you would need to use a Macro. This would take the values for a and b entered in a Form, create the sum and put that value back in the Form. Then insert a record in the Table with these values.