How do I calculate the difference between 2 fields - ongoing

  • Thread starter Darrell Childress
  • Start date
D

Darrell Childress

I have a table that has the following pertinent fields:

Date, Qty

Each day a new record is added with that date and the new quantity. I
need to write a query that will show the difference in the most recent
date and the next-to-most recent date, but I cannot figure out how to do
that. Any help would be appreciated.
Thanks,
Darrell
 
G

Guest

You can use some code, create a function that return the difference.

Function aaaa()
Dim MyDB as databse, MyRec as recordset, FirstQty as double, SecondQty as
double

Set MyDB = codedb
Set MyRec = mydb.openrecordset("Select Top 2 Date, Qty From MyTable Order By
Date Desc")
FirstQty = MyRec!Qty
MyRec.movenext
SecondQty=MyRec!Qty
aaaa = FirstQty - SecondQty

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top