Update Field

ViRi

Registered User.
Local time
Today, 09:54
Joined
Jan 31, 2006
Messages
44
I have 2 numeric fields one called Sold the other SoldSum on a form called frmProduct.

Sold receives a value from another form when the user clicks on a button.

I would like SoldSum to add the values that Sold receives every time the Sold value changes

I have tried this code on the AfterUpdate event of the Sold Field

Code:
Dim Sold
Dim SoldSum

Set Sold = Forms("frmProduct")("Sold")
Set SoldSum = Forms("frmProduct")("SoldSum")
 
SoldSum.Value = SoldSum + Sold

I don't get errors but the SoldSum field is blank

ViRi
 
ViRi said:
I have 2 numeric fields one called Sold the other SoldSum on a form called frmProduct.

Sold receives a value from another form when the user clicks on a button.

I would like SoldSum to add the values that Sold receives every time the Sold value changes

I have tried this code on the AfterUpdate event of the Sold Field

Code:
Dim Sold
Dim SoldSum

Set Sold = Forms("frmProduct")("Sold")
Set SoldSum = Forms("frmProduct")("SoldSum")
 
SoldSum.Value = SoldSum + Sold

I don't get errors but the SoldSum field is blank

ViRi

Code:
SoldSum.Value = SoldSum + Sold

Have you tried adding .Value to SoldSUm and Sold. That way it can get the value of those fields.

Code:
SoldSum.Value = SoldSum.Value + Sold.Value
 
ViRi,

You really shouldn't store a calculated value, but you need syntax
like this.

Forms!frmProduct!SoldSum = Forms!frmProduct!SoldSum + Me.Sold

I would assume that you are using the BeforeUpdate or AfterUpdate
event of the Sold control. What happens if they change the sold
value:

SoldSum = $50 <-- Original entry
SoldSum = $50 + $40 <-- Sold price changed to $40 (Sum is wrong)

It can get pretty complicated to keep things in "synch". It's
better to just sum the values with a Query/DSum function when
you need them. A LOT less code (and errors).

Wayne
 
Thanks for your interest

SoldSum = $50 <-- Original entry
SoldSum = $50 + $40 <-- Sold price changed to $40 (Sum is wrong)

Using the above the SoldSum should change to $90 and that is fine I'm not adding the Sold Field this will just hold the values that SoldSum should add up. The problem is that nothing happens to the SoldSum field with the code in the After Update event of the Sold field.
 
ViRi,

The button should do something like this:

Me.Sold = Forms![ThatOtherForm]![ThatOtherField]
Me.SoldSum = Me.SoldSum + Me.Sold

ThatOtherForm must be open.

Wayne
 

Users who are viewing this thread

Back
Top Bottom