Ask Your Question

Base math operation inside a form

asked 2015-10-20 12:58:01 +0200

gagginaspinnata gravatar image

Hello, let's assume I've a table with 4 fields:

  1. id primary key
  2. a integer
  3. b integer
  4. 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 ?

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2015-10-23 12:50:05 +0200

BlueBike gravatar image

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.

edit flag offensive delete link more

answered 2015-10-26 12:21:05 +0200

peterwt gravatar image

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.

edit flag offensive delete link more

answered 2015-10-24 08:57:07 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

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:


edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-10-20 12:53:26 +0200

Seen: 1,590 times

Last updated: Oct 26 '15