By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,316 Members | 2,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,316 IT Pros & Developers. It's quick & easy.

Count Distinct Response

P: n/a
Someone (Kevin i think) was looking for a way to do a distinct count,
not sure if i'm using this groups thing right - was trying to supply
answer. Anyway, this is a function i wrote for it... hope it gets to
you. just copy and past it into a module and call it as you would

Public Function CountDistinct(Field As String, QueryOrTableName As
String, AdditionalCriteria As String)

Dim dbs As Database
Dim rst As Recordset

Set dbs = CurrentDb

If Not AdditionalCriteria = "" Then
Set rst = dbs.OpenRecordset("select distinct " & Field & "
from " & QueryOrTableName & " Where " & AdditionalCriteria)
Set rst = dbs.OpenRecordset("select distinct " & Field & "
from " & QueryOrTableName)
End If

CountDistinct = rst.recordcount

End Function
Nov 13 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.