Thanks for the reply Fred.
Here is the actual SQL query that I would like to run, along with the
DLookup...
select count (*) As Total
From tblHWConfig
Where (LeaseEndDate - Now() < 90)
=DLookup ("Count (*)", "tblHWConfig", "(LeaseEndDate - Now() < 90))
Do I simply use the DLookup statement as the control source for the text box?
Note that as it is right now, the DLookup statement produces an #Error on
the report. Not sure why...
~~Rich
No.
You are using a query to return the count value.
To show this value in the report, you simply use DLookUp (without
criteria) to read that one value.
For the DLookUp, it's the [Total] column that contains the count
value.
tblHWConfig appears to be the name of the table that is being counted,
not the name of the query itself. You must use the query name here.
Criteria in the DLookUp in the report is not needed as the query is
returning just the one value.
So...
=DLookup ("[Total]", "TheQueryName")
Make sure the name of this control in the report is NOT the same as
the name of any field used in it's control source expression.
Note: In your query criteria, because Now() contains the time of day
as well as the date, in some instances the result might vary according
to the time of day you run this. Use Date() instead of Now().
Where (LeaseEndDate - Date() < 90)
You could also by-pass the query entirely and use DCount on the table
instead:
In the report:
=DCount("*","tblHWConfig","[LeaseEndDate] - Date() < 90")
Note that in the DCount above, "[LeaseEndDate] - Date() < 90" is
enclosed entirely within double quotes.
Make sure the name of this control in the report is NOT the same as
the name of any field used in it's control source expression.