First of all, thank you all very much for the help.
Ron,
The function you wrote works, but it doesn't help me, since I want to count
distinct rows using a filter (and not all distinct rows). My filters are
exactly the 'Group By' I am using in the report (it began as a form, but now
it's a report...), so if there was an easy way counting distinct rows using
access, the filters I need would have automatically been there...
Come to think of it, if there was a way to ask access how many groups were
under a certain 'Group By' it would solve my problem. For example, if I am
grouping on three levels: level0, level1 ans level2, is there a way to ask
access how many groups of level1 appeared under level0?
thanks again.
Ron Weiner said:
Here is a Function that I think does what he wants.
Public Function CountDistinctRows(strTable As String, strColumn As String)
As Long
Dim rs As ADODB.Recordset
Dim strSql As String
strSql = "Select Distinct " & strColumn & " From " & strTable
strSql = strSql & " Where not " & strColumn & " Is Null"
Set rs = New ADODB.Recordset
rs.Open strSql, CurrentProject.Connection, adOpenStatic
rs.MoveLast
CountDistinctRows = rs.RecordCount
rs.Close
Set rs = Nothing
End Function
In the Text box Control Source = countDistinctRows ("Table","Column") to
return the count of distinct rows where the rows are Not Null.
Ron W
That doesn't work in Access, Jeff.
dshemesh: I don't believe there's anyway to do what you want, unless you
want to have a separate query that selects the distinct rows, and does a
count on that subquery.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Count DISTINCT ...?
Jeff Boyce
<Access MVP>
Hello,
Is there a way to count distinct rows using the controlSource property
of
a
textbox?
writing: =count([orderId]) returns all the OrderId's, and I want to
count
only the distinct orderId's.
thanks