Automatic update of a field

Bizkaiko

Registered User.
Local time
Today, 17:10
Joined
Jan 17, 2005
Messages
31
Hi!
I've a form with the fields PriceA, priceB, priceC and a field Total.
I set the source control of Total =priceA+B+C 'cause it's always the same operation and in this way I didn't need to write the same code in priceA_afterUpdate, priceB_afterupdate etc. and when I change a value of a price it can display auomatically the new value of total.
The problem is that I've another field FinalTotal which value depends on the value of Total and on other parameters linked to the OrderType (so I can't set FinalTotal=Final*parameter1 'cause it can be even =Total*(parameter2+parameter3) or =Total+(parameter4) etc.
I tried to write the code
"if OrderType=1 then... " in the Total_afterUpdate and in total_Change() events, but the field FinalTotal is always blank (I think 'cause there's no manual update or change).
Is it necessary copy the code in the PriceA_afterupdate, priceB_afterupdate etc? If they were only 3 i coud do it, but the parameters determining the field Total are a lot! :(
 
Your comments describing the variable number of parameters tells me your structure might not be normalized.

First rule: Always normalize your DB
Second rule: Never store a total that you can recompute later.

Now, the "computed control" - your form's [Total] textbox - is done correctly. You are not storing it. You are computing in on-the-fly. :)

The description of your problems with the FinalTotal field, though, tells me that you have a non-normalized contributor to this computation. If it were properly normalized, you would be able to write a summation query or use a DSum function to do it. It would be no sweat whatever.

What are the sources of these parameters you describe as potential contributors to this total?
 
The DB is normalized: I just tried to explain the problem using a simple example.
the Total which is a sum of prices is not stored, but the users need to see it to "control" the order (I don't know why, but they told me so).
They just insert some parameters and the total is calculated automatically with an expression that doesn't change; but they need to see even this "FinalTotal", and how to calculate it depends on the type of order selected(so it can be =total*a+b+c, or =total*b+c or =total*e...) . So I can't set a source control for the field.
I tried to write the code in the total_afterUpdate event, but the problem is that the field "total" is not updated 'cause it's set automatically: I could write the code in every parameter_afterUpdate() (and I'd do it if they were only 3-4), but I'd like to know if there's a way to make access recognize the value of "total" is changed and re-calculate the FinalTotal.
(I tried even the FinalTotal_MouseMove etc, and when I move the mouse over the field, it calculates the correct value without problems, so it's only a problem to display it automatically)


[The parameters which contribute to the "total" depend on other parameters and queries...]
 
Last edited:

Users who are viewing this thread

Back
Top Bottom