DCount Syntax

D

DS

I have DCount expression in a unbound field on a continous form. I'm
trying to have it count how many other [LineID] matches the [LineID] of
the current Record.

=DCount("LineID","SalesDetails","[LineID]=[LineID]")

Thanks
DS
 
D

Dirk Goldgar

DS said:
I have DCount expression in a unbound field on a continous form. I'm
trying to have it count how many other [LineID] matches the [LineID]
of the current Record.

=DCount("LineID","SalesDetails","[LineID]=[LineID]")

You'll get closer with this:

=DCount("LineID","SalesDetails","[LineID]=" & [LineID])

but on a continuous form it will still only show you -- for all rows --
the value that is calculated for the current record. So it will show
you the same value for all rows, but change that as you navigate from
one row to another.

You could base the form on a query that woul calculate that for each
record, though. Something like:

SELECT
SalesDetails.*,
(
SELECT Count(*) FROM SalesDetails T
WHERE T.LineID = SalesDetails.LineID
) AS LineCount
FROM
SalesDetails;
 
J

John Vinson

I have DCount expression in a unbound field on a continous form. I'm
trying to have it count how many other [LineID] matches the [LineID] of
the current Record.

=DCount("LineID","SalesDetails","[LineID]=[LineID]")

This will count the records in the SalesDetails table for which the
LineID in that record is equal to itself - all of them, in other
words.

Pull the current record's LineID out of the quotes:

=DCount("*", "[SalesDetails]", "[LineID] = " & [LineID])

Thus if the current record has LineID equal to 1245, the criteria
argument to DCount will be

[LineID] = 1245

and you'll get the count you want.

I use * rather than LineID since you're counting matching records, not
lineID's - the results will be the same, though.

John W. Vinson[MVP]
 
D

DS

John said:
I have DCount expression in a unbound field on a continous form. I'm
trying to have it count how many other [LineID] matches the [LineID] of
the current Record.

=DCount("LineID","SalesDetails","[LineID]=[LineID]")


This will count the records in the SalesDetails table for which the
LineID in that record is equal to itself - all of them, in other
words.

Pull the current record's LineID out of the quotes:

=DCount("*", "[SalesDetails]", "[LineID] = " & [LineID])

Thus if the current record has LineID equal to 1245, the criteria
argument to DCount will be

[LineID] = 1245

and you'll get the count you want.

I use * rather than LineID since you're counting matching records, not
lineID's - the results will be the same, though.

John W. Vinson[MVP]
Thanks, John....It worked great!!!
DS
 
Top