View Full Version : Calculation using just the last two records


zoohoot
05-10-2005, 01:43 PM
Hello All. I am new to these forums but appreciate very much any feedback on my question:

I have a table in my database that retains weights for our clients. The table contains the following fields:

ID
ResidentID (relates to the residents table that has name, etc.)
Date
Weight

Each month with a client is weighed, the date and weight is entered into a subform.

I am attempting to perform a calculation in a query and/or report that would automatically give the weight gain/loss between the last two entries.

Any suggestions on how to do this? There is of course the "last" function, but I cannot figure out how to get the record just prior to the last.

Mile-O
05-10-2005, 01:53 PM
Any suggestions on how to do this? There is of course the "last" function, but I cannot figure out how to get the record just prior to the last.

Two solutions:

One, you could use a recordset and use some VBA to get what you want.
Two, you can create one query, sort descnding, and ensure that the SELECT TOP 2 is set. You can then use DMax() and DMin() - or a recordset again - to get both dates.

zoohoot
05-10-2005, 01:57 PM
Two solutions:

One, you could use a recordset and use some VBA to get what you want.
Two, you can create one query, sort descnding, and ensure that the SELECT TOP 2 is set. You can then use DMax() and DMin() - or a recordset again - to get both dates.

Brilliant! I was not even aware of the select top property. Thank you so much!