a b prev(a) prev(b)
1 2 null null
3 4 1 2
5 6 3 4
The are some articles in knowledge base ,but none will help me.
Thank you
Jack
Check Access Help on SubQuery.
Extract from one of my earlier replies on a similar question:
********
It is actually not trivial as you want to refer to 2 Records as the same
time. Try a Self Join with a Subquery. The SQL String should be something
like:
SELECT [tblReading].[Datefield], [tblReading].[Reading],
[tblReading_1].[Datefield], [tblReading_1].[Reading],
[tblReading].[Reading] - [tblReading_1].[Reading] AS Usage
FROM tbltblReading, tblReading AS tblReading_1
WHERE tblReading_1.[Datefield] =
(SELECT Max([tblReading_2].[Datefield])
FROM tblReading AS tblReading_2
WHERE [tblReading_2].[Datefield] < tblReading.[Datefield]);
Alternatively, you can just create a Recordset sorted by date ASC, move to
first Record (if Recordset is not empty), store Reading in a Variable
"lngPrevReading". Move to second Record, (Reading - lngPrevReading) gives
you the difference (nett change). Save Reading as lngPrevReading. Move to
next Record and repeat the process until EOF.
HTH
Van T. Dinh
"Mike McGonagle" <mi...@rirrc.org> wrote in message
news:#JFZ$rJWBHA.1468@tkmsftngp07...
> I'm working on an application where I enter the reading from a meter. I
> would like to have the application automatically calculate the net change
> from the meter reading recorded in the previous record.
>
> This sounds simple enough but I can't for the life of me figure out how to
> do this in Access.
>
> Any suggestions, sample code would be greatly appreciated.
>
>
********
--
HTH
Van T. Dinh
MVP (Access)
"JD" <t@b> wrote in message news:eLvRJm0#BHA.1880@tkmsftngp04...