Welcome to Access World! We're so happy to have you join us as a member of our community. As the most active Microsoft Access discussion forum on the internet, with posts dating back more than 20 years, we have a wealth of knowledge and experience to share with you.
We're a friendly and helpful community, so don't hesitate to ask any questions you have or share your own experiences with Access. We're here to support you and help you get the most out of this powerful database program.
To get started, we recommend reading the post linked below. It contains important information for all new users of the forum:
Nobody else asked, so I will: Does each record have a date in it?
To do what you ask, it is necessary to have a relevant date within each record. If you do, then the suggestions above have a good chance to help you. If you have no date in the records, you can't compute such a thing, because there is no "inherent" date in an arbitrary record.
Although either a subselect or a self join can be used to solve this problem, the solutions require a unique ID that can be used to order the records. The self join is more efficient than the subselect if that works for you because Access is very inefficient at evaluating sub queries.
The most efficient method is to use a report. With queries, the recordsets are moving targets which is why the calculation is so awkward and requires the use of unique sequence numbers to properly order the recordset but with reports, the process is straight sequential logic. You still have to sort the records but you don't need a unique sequence number since the records are processed sequentially rather than as a set. You can use the on Print event to calculate the difference between the current record and the previous record. You need to save each record as it is printed to the "previous" variable. If the previous variable is empty, then just save the current value as previous.
@sargon - since we don't know how those things are defined, it is possible that you have incorrectly referenced them. However, traditionally, that statement would read:
But I have to ask whether the third reference to PaymentDate (between ampersands) comes directly from a form or is that in a query context? It is possible that Access doesn't know where to get that value.
As a side note, you are certainly welcome to do what you did, but you often get better results by starting a new thread rather than tacking on to an older thread (such as this one which started in 2023.)
I am tring to replicate "How to Calculate Date Differences Between Consecutive Records in Microsoft Access" from Youtube channel Computer Learning Zone