DLast function problem

mikejaytlabustro

Access Database 2007 PH
Local time
Tomorrow, 01:56
Joined
Feb 11, 2013
Messages
93
Fields: Date PumpNo PreviousReading CurrentReading
Jul 1 101 0 100
Jul 2 101 100 200
Jul 3 101 200 300

PumpNo Afterupdate event:

PreviousReading=DLast("CurrentReading", "MyTable", "[PumpNo]=[PumpNo].Text")

Problem:

I have many PumpNo and sometimes changes in PumpNo inputs could not be avoided.
For example on Jul 3, i want to change PumpNo 101 to 102 then access will give me the last current reading of PumpNo 102. There was no problem regarding this action, but when i realized that it should be Pump 101 and change back the value to 101 again, access gives me 300 instead of 200.

I think there should be an additional vba code for this to refresh or update the DLast value of PumpNo.

Thank you in advance for your help.
 
Code:
PreviousReading=DLast("CurrentReading", "MyTable", "[PumpNo]=" & Me.[PumpNo])
 
you shouldn't be storing previous reading in your table - it is the same as the current reading in the previous record.

What happens if in error you enter the 2nd row as Aug 3, and later after several more entries realise your error and correct it?

Also DLast without a sort order will give a random return based on the current order of the table (it does not mean last entered) so cannot be relied on
 

Users who are viewing this thread

Back
Top Bottom