jtfalk said:
Hello,
I have an inventory database. I have the sum of apples in my last record
and
want to subtract apples today from it:
Total apples (in last record) = 25
(new record) sell 5 apples = total apples = 20
me.total_apples = me.sell_apples + (last record me.total_apples)
How can I get that last records me.total_apples.
I do not have an open internet access so I can not go see alan browns web
page only microsoft web pages.
In order to even begin to talk about getting values from a previous record,
you have to define what "previous" means in the context of your table. For
most purposes, Access treats a table as a "big bag of records", with no
defined order -- most specifically, records are not inherently ordered by
entry sequence. In any situation where you want to talk about "previous" or
"next" records, you must specify a sort order for the records -- for
example, in the ORDER BY clause of a query. And that sort order must be
defined in terms of data in the records.
If you need to process records in order of entry, then you need to have a
date/time field in the records that is set to Now() whenever a record is
entered. If your records have a consecutive autonumber primary key, then In
carefully restricted circumstances, you might use that key field as an
indicator of the entry sequence. However, not all tables use autonumber
keys, and even in those that do, autonumbers can become random, not
consecutive, under certain circumstances. So if you care about entry
sequence, you really ought to use a date/time field to store the
information.
Once you have established a field that you can use to determine the sequence
of records, you don't really need to store the current inventory total in
any record. It can always be calculated on the fly by adding up the
transaction quantities of all records entered up through the current one.
In some cases, it may be useful to store it for efficiency's sake, but that
runs the risk of having inconsistent data if, for example, somebody modifies
one of the earlier records without recalculating the total in all subsequent
records. So I don't recommend storing this calculated data unless you find
you really need to.