Counting problem

ino_mart

Registered User.
Local time
Today, 08:09
Joined
Oct 7, 2009
Messages
78
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?
 
Last edited:
You're using a Continuous View form, and txtAmount is an Unbound field. This is the normal behavior for an Unbound control on this type of form. You need to add a field to the underlying table then, in Form Design View, select txtAmount and goto Properties - Data and set the Control Source to that newly created field.

If the form is based on a Query, you'll have to go into the Query and add the field to it before assigning the field as a Control Source to the textbox.
 

Users who are viewing this thread

Back
Top Bottom