Okay, lets break it down.
Remove the criteria for now.
Instead type this into a fresh column in the Field row:
(SELECT Max(Dupe.[Date]) FROM [Financial Data] As Dupe)
Does that work? Showing the most recent date? An alternative expression:
(SELECT TOP 1 Dupe.[Date]
FROM [Financial Data] As Dupe
ORDER BY Dupe.[Date] DESC, Dupe.[ID] DESC)
where you need to replace [ID] with the name of your primary key field.
Once you have that expression working, get the DateAdd() working as well
(still in the Field row):
DateAdd("d", -60, Nz(xxx, Date()))
where the xxx represents the entire expression you got working.
Once that's working, you can move the expression back into the Criteria row
again.
(You should also be aware thate Date is a reserved word in JET and in VBA,
so not a good name for a field.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
WhytheQ said:
ok I've added in the criteria and it looks like the below:
=DateAdd("d", -60,Nz((SELECT Max([Date]) FROM [Financial Data] As
Dupe),Date())
Where the table is 'Financial data' and the Field is 'Date': I get a
warning about invalid syntax when I try to enter this criteria.
Allen said:
Nz() test if the value is Null.
If so, it replaces the Null with the 2nd argument.
Nice one Allen: I'll give that a go.
I'm new to Access/SQL so I'll have to look into this Nz function you've
used - looks like it might be something similar to Indirect used in
Excel.
Allen Browne wrote:
Try:
=DateAdd("d", -60,Nz((SELECT Max([MyDate]) FROM [MyTable] As
Dupe),
Date())
Replace MyDate with the name of the date field, and MyTable with the
name
of
the table.
If subqueries are new, see:
How to Create and Use Subqueries
at:
http://support.microsoft.com/?id=209066
I'm using the following criteria in my query:
=DateAdd("d",-60,Date())
...basically returns a date 60 days before today. Really I want it
to
return the date 60 days before the highest(max) date in the date
field,
which may not be the same as today if the database hasn't been
updated.
HELP!!