On May 29, 9:02 am, Laura <laurajayne.coz...@peterborough.gov.uk>
wrote:
Hi Jason
Forget it - I copied your code into an access query rather than a VBa
module and it works 100% spot on! Thanks so much for saving me and my
collegaues so much time!
Laura
You got it. It's SQL - the code that's used in queries.
SELECT A.CLIENT_ID,
A.START_DATE,
A.END_DATE,
DATEDIFF("d",[END_DATE],[NEXT_START]) AS DAYS_BETWEEN
FROM LAURAJAYNE AS A;
It selects the client_id, start_date, and end_date from a table called
"LAURAJAYNE". That table is given an alias of "A" (because it's
easier to type and read).
This section is a little more complicated:
NZ((SELECT MIN(START_DATE)
FROM LAURAJAYNE AS B
WHERE B.START_DATE A.END_DATE
AND A.CLIENT_ID = B.CLIENT_ID),DATE()) AS
NEXT_START,
NZ is a function that selects the first of a list of values that is
not null. The query selects the first start date from LAURAJAYNE
(aliased as B) that has a matching clientid and is greater than the
current end_date. Because there may be no record that has a greater
start date, the nz function will then pick DATE(), which returns
todays date.
Cheers,
Jason Lepack