Saving Calculated Data in a Table

  • Thread starter Thread starter SamusAran
  • Start date Start date
S

SamusAran

Hope someone can give me some guidance.

I have a small TimeKeeping App that I am putting together and I have need to
save calculated hours for reports and other calculations in other reports and
forms. I know you are 'Supposed' to recalc when you need it instead of
storing the data but it would really make my life easy if I could store each
weeks hours in a table which could be used by others for various reports and
queries.

Right now I can eaily add 7 days worth of time together to come up with a
simple total on the form but I can't seem to get the "total" to save with the
rest of the data in the table.

Any help would be greatly appreciated.

Thanks
 
In a well-designed database it is very unlikely it would be easier to store
the calculation result than perform the calculation as needed. However, if
you insist on doing so you would need a way of knowing which records are for
which date, and to add up only the records within that time range. If you
can do that there is no reason to store the calculation. Without knowing
anything about the structure of your database it is impossible to suggest
anything specific.
 
There really is no justification for storing calculated numbers.
Storing them wasts space, it takes long to store and retrieve them than the
calculation does, and you have the distinct possibility that the stored value
will become incorrect because of time passage, or other values used in the
calculation get changed.

One way to make it as simple as possible is to write a public function that
performs the calculation and returns the value. You can call it from forms,
in queries, on reports, and in other calculations. That way, the
calculation, regardless of where used, is consistent. Also, you don't have
to rewrite the calculation multiple times. This technique, in fact, is very
good design. Not only is the results consistent, but if a business rule
dictates chaning the calculation, you only have to modify and test it in one
place.
 
Back
Top