Hello!
Tables:
The first table (table1) looks like this:
ID | ItemName | ItemCount | TotalValue_double |
---|---|---|---|
0 | Item_A | 1 | -1 |
1 | Item_B | 41 | -1 |
The second table (table2) looks like this:
ID | ItemName | PercentagePerItem |
---|---|---|
0 | Item_A | 0.01 |
1 | Item_B | 0.05 |
Goal:
I want to create a form and insert the data, but TotalValue_double from table1 needs to be calculated first. It is beeing calculated by multiplying ItemCount from table1 with PercentagePerItem from table2.
Form:
So the form would look like this:
ItemName [ TEXTBOX ]
ItemCount [ TEXTBOX ]
TotalValue_double [ TEXTBOX ]
Desired Result:
I type in e.g. “Item_A” into the ItemName text box and any number for ItemCount, e.g. 10. The TotalValue_double should be calculated by multiplying the ItemCount from Item_A (table1) with the PercentagePerItem from Item_A (table2). It would be like this:
10*0.01 = 0.1
where 0.1 will be stored in TotalValue_double from table1. I need the TotalValue_double stored, because I’m going to retreive it later in another step and calculate something else with it.
(PercentagePerItem from table2 isn’t going to change / the value stays the same. It’s like a constant.)
SQL to calculate and display the result in a form
After testing and researching for quite a long time, I figured out how to calculate the result I need using a query and store the result in a column that I create using this query. Every time when I enter the data in the form and save it (leaving out TotalValue_double) the query calculates the result and shows it. But the value is never actually stored in table1 where it belongs.
SQL Code:
SELECT
"table1"."ID",
"table1"."ItemName",
"table1"."ItemCount",
[ItemCount]*[PercentagePerItem] AS "TotalValue_double"
FROM "table1", "table2"
WHERE "table1"."ItemName" = "table2"."ItemName"
Please help me in calculating the TotalValue_double and storing it in the table. Also, I don’t necessarily need to see the calculated value in the form. It just needs to be calculated correctly and be stored in the table.
Also, since I can’t seem to understand macros it would be great if a “no macro solution” exists.
Thank you for your time!