Do action for each record

  • Thread starter Thread starter Darcy
  • Start date Start date
D

Darcy

I have a form that allows me to edit the records of a table.

One of the records is calculated.

So I therefore have to calculated it every time the user makes a change.

The compromise is to do it in the after_update (or should I use
before_update)?

Worse yet, there are several sub forms. If a change is made in the Subform.


Any ideas on how I can do this?

If I have to, I'll just do the calculation unconditionally each time the
user tries to leave the record but what event should I use for that?

Thanks in advance.
 
I have a form that allows me to edit the records of a table.

One of the records is calculated.

Ordinarily one would not store calculated fields in a table. Are you
certain that it is necessary to do so at all?
So I therefore have to calculated it every time the user makes a change.

The compromise is to do it in the after_update (or should I use
before_update)?

Before_Update if the record being updated contains the calculated
field (it's already been written to disk and cannot be changed in the
Form's AfterUpdate event).
Worse yet, there are several sub forms. If a change is made in the Subform.

If a change is made... what??
Any ideas on how I can do this?

If I have to, I'll just do the calculation unconditionally each time the
user tries to leave the record but what event should I use for that?

Form_BeforeUpdate.
 
Hello John,

Thanks for the reply.

I see your suggestion for unconditionally running code each time the user
leaves the record (Form_beforeUpdate).

This only runs IF a change was made on the form so its not unconditional.

The difficulty I'm having is that when changes are made on the Subforms, I
want to run a calculation on the main form. The Form_beforeUpdate doesn't
seem to run when I make changes on the subforms so my calculation isn't
being run at all in those cases.

Darcy
 
The difficulty I'm having is that when changes are made on the Subforms, I
want to run a calculation on the main form. The Form_beforeUpdate doesn't
seem to run when I make changes on the subforms so my calculation isn't
being run at all in those cases.

Run the code in each Subform's AfterUpdate event as well, then.
 
When would one store a values in a calculated field?

Can you give examples?

Thanks

Lee
 
When would one store a values in a calculated field?

Can you give examples?

It's appropriate when you need to capture a "snapshot" of the value at
a particular time. A classic example is an ExtendedPrice in an Orders
application; if you have fields for Quantity and UnitPrice, at first
blush one would say to just calculate EP: [Quantity] * [UnitPrice]
dynamically in a Query.

However, in the context of an order, what's needed is the Extended
Price *using the Unit Price that was in effect at the time of
purchase*. Since unit prices can change, the expression would not give
the actual Extended Price which was charged; you need to store the
derived field to keep a record of what price WAS in fact charged.
 
Back
Top