All
Hereby a simple representation of my problem. I created a table with two fields (Product and Price) which contains some records
Product..............Price
Product A..........€1.20
Product B..........€1.80
Product C..........€5.00
Next I created a form based on this table. In the section "Details" of this form I created a button "ADD". If you run the form, the button "ADD" is visible behind every record.
Product..............Price
Product A..........€1.20.....ADD
Product B..........€1.80.....ADD
Product C..........€5.00.....ADD
In section "Form Footer" I created a field "Total".
In case you press on the button "ADD", next code runs:
me.txtTotal=me.txtTotal + me.txtPrice
This works as expected. If I press on ADD behind product A, the value of me.txtTotal changes to €1.20. If I then press on ADD behind product C, me.txtTotal is adjusted to €6.20 (= €1.20 + €5.00).
In next step I added a field txtAmount behind the button "ADD" to indicate how many items of this product are ordered. What I should get is something like:
Product...............Price............Amount
Product A..........€1.20.....ADD.....2
Product B..........€1.80.....ADD.....1
Product C..........€5.00.....ADD.....3
Totaal = €19.20
I thought I could solve this easily by changing the code behind button ADD.
me.txtTotal=me.txtTotal + me.txtPrice
me.txtAmount=me.txtAmount + 1
This seems not to be the solution. With this code, Access puts the same number in every textfield of txtAmount. I get next result:
Product...............Price.............Amount
Product A..........€1.20.....ADD.....6
Product B..........€1.80.....ADD.....6
Product C..........€5.00.....ADD.....6
Total = €19.20
I think this is caused as txtAmount is not handled as an array. How can I solve this?
Hereby a simple representation of my problem. I created a table with two fields (Product and Price) which contains some records
Product..............Price
Product A..........€1.20
Product B..........€1.80
Product C..........€5.00
Next I created a form based on this table. In the section "Details" of this form I created a button "ADD". If you run the form, the button "ADD" is visible behind every record.
Product..............Price
Product A..........€1.20.....ADD
Product B..........€1.80.....ADD
Product C..........€5.00.....ADD
In section "Form Footer" I created a field "Total".
In case you press on the button "ADD", next code runs:
me.txtTotal=me.txtTotal + me.txtPrice
This works as expected. If I press on ADD behind product A, the value of me.txtTotal changes to €1.20. If I then press on ADD behind product C, me.txtTotal is adjusted to €6.20 (= €1.20 + €5.00).
In next step I added a field txtAmount behind the button "ADD" to indicate how many items of this product are ordered. What I should get is something like:
Product...............Price............Amount
Product A..........€1.20.....ADD.....2
Product B..........€1.80.....ADD.....1
Product C..........€5.00.....ADD.....3
Totaal = €19.20
I thought I could solve this easily by changing the code behind button ADD.
me.txtTotal=me.txtTotal + me.txtPrice
me.txtAmount=me.txtAmount + 1
This seems not to be the solution. With this code, Access puts the same number in every textfield of txtAmount. I get next result:
Product...............Price.............Amount
Product A..........€1.20.....ADD.....6
Product B..........€1.80.....ADD.....6
Product C..........€5.00.....ADD.....6
Total = €19.20
I think this is caused as txtAmount is not handled as an array. How can I solve this?
Last edited: