Counting unique records

J

jj

I have created a database of students who are attending our summer program.
I have a form, based on the table of applicants, that has a subform attached
where staff members can enter comments. The subform is linked to it's own
table. I would like to count the number of applicants that I have comments
on. If I use the =Count(*), it counts every record. I have set up a query
that counts the unique field, student ID, in the table. How can I count the
number of unique student IDs that are in the subform table in a report?
 
S

strive4peace

Hi jj,

in a form or report, put this in the footer:
=Sum( IIF(IsNull([comment_controlname]),0,1)

WHERE
comment_controlname is the Name property of the control that holds the
comment

In a query:
field --> NumComment: dSum("[studentID]","[Tablename]", "Not
IsNull([comment_fieldname])")

WHERE
studentID is the name of your student id fieldname
Tablename is the name of your table
comment_fieldname is the name of your comment fieldname

Warm Regards,
Crystal

*
:) have an awesome day :)
*
 
J

Jackie L

Create a query (qryCountStudents) with the Comment table. Bring down the
Student Id field and View - Totals. Keep Group by for that field.

Now, on your report you can create a field with the Control Source of:
=DCount("StudentID","qryCountStudents")

Hope this helps,
Jackie
 
K

KARL DEWEY

Try this editing it to your actual table and field names ---
SELECT Count([StudentID]) AS CountOfStudentID
FROM [table of applicants] LEFT JOIN [Comments] ON [table of
applicants].[StudentID] = [Comments].[Comment]
WHERE ((([Comments].[Comment]) Is Null));
 
K

KARL DEWEY

Corrected the join ---
Try this editing it to your actual table and field names ---
SELECT Count([StudentID]) AS CountOfStudentID
FROM [table of applicants] LEFT JOIN [Comments] ON [table of
applicants].[StudentID] = [Comments].[StudentID]
WHERE ((([Comments].[StudentID]) Is Null));

--
KARL DEWEY
Build a little - Test a little


KARL DEWEY said:
Try this editing it to your actual table and field names ---
SELECT Count([StudentID]) AS CountOfStudentID
FROM [table of applicants] LEFT JOIN [Comments] ON [table of
applicants].[StudentID] = [Comments].[Comment]
WHERE ((([Comments].[Comment]) Is Null));

--
KARL DEWEY
Build a little - Test a little


jj said:
I have created a database of students who are attending our summer program.
I have a form, based on the table of applicants, that has a subform attached
where staff members can enter comments. The subform is linked to it's own
table. I would like to count the number of applicants that I have comments
on. If I use the =Count(*), it counts every record. I have set up a query
that counts the unique field, student ID, in the table. How can I count the
number of unique student IDs that are in the subform table in a report?
 
D

Douglas J. Steele

I don't think so, Karl. Count([StudentID]) is going to return exactly the
same as Count(*).

Try:

SELECT Count([StudentID]) AS CountOfStudentID
FROM
(SELECT DISTINCT [table of applicants].StudentID FROM
[table of applicants] LEFT JOIN [Comments] ON [table of
applicants].[StudentID] = [Comments].[StudentID]
WHERE [Comments].[StudentID]) Is Null)


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


KARL DEWEY said:
Corrected the join ---
Try this editing it to your actual table and field names ---
SELECT Count([StudentID]) AS CountOfStudentID
FROM [table of applicants] LEFT JOIN [Comments] ON [table of
applicants].[StudentID] = [Comments].[StudentID]
WHERE ((([Comments].[StudentID]) Is Null));

--
KARL DEWEY
Build a little - Test a little


KARL DEWEY said:
Try this editing it to your actual table and field names ---
SELECT Count([StudentID]) AS CountOfStudentID
FROM [table of applicants] LEFT JOIN [Comments] ON [table of
applicants].[StudentID] = [Comments].[Comment]
WHERE ((([Comments].[Comment]) Is Null));

--
KARL DEWEY
Build a little - Test a little


jj said:
I have created a database of students who are attending our summer
program.
I have a form, based on the table of applicants, that has a subform
attached
where staff members can enter comments. The subform is linked to it's
own
table. I would like to count the number of applicants that I have
comments
on. If I use the =Count(*), it counts every record. I have set up a
query
that counts the unique field, student ID, in the table. How can I
count the
number of unique student IDs that are in the subform table in a report?
 
J

jj

I'm testing this and it seems to work. Thanks for your help.
--
jj Trying to learn


strive4peace said:
Hi jj,

in a form or report, put this in the footer:
=Sum( IIF(IsNull([comment_controlname]),0,1)

WHERE
comment_controlname is the Name property of the control that holds the
comment

In a query:
field --> NumComment: dSum("[studentID]","[Tablename]", "Not
IsNull([comment_fieldname])")

WHERE
studentID is the name of your student id fieldname
Tablename is the name of your table
comment_fieldname is the name of your comment fieldname

Warm Regards,
Crystal

*
:) have an awesome day :)
*

I have created a database of students who are attending our summer program.
I have a form, based on the table of applicants, that has a subform attached
where staff members can enter comments. The subform is linked to it's own
table. I would like to count the number of applicants that I have comments
on. If I use the =Count(*), it counts every record. I have set up a query
that counts the unique field, student ID, in the table. How can I count the
number of unique student IDs that are in the subform table in a report?
 
S

strive4peace

you're welcome, jj ;) happy to help


Warm Regards,
Crystal

*
:) have an awesome day :)
*
 
P

Pieter Wijnen

Sometimes I miss Oracles Count(Distinct .. )

;-) Pieter

Douglas J. Steele said:
I don't think so, Karl. Count([StudentID]) is going to return exactly the
same as Count(*).

Try:

SELECT Count([StudentID]) AS CountOfStudentID
FROM
(SELECT DISTINCT [table of applicants].StudentID FROM
[table of applicants] LEFT JOIN [Comments] ON [table of
applicants].[StudentID] = [Comments].[StudentID]
WHERE [Comments].[StudentID]) Is Null)


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


KARL DEWEY said:
Corrected the join ---
Try this editing it to your actual table and field names ---
SELECT Count([StudentID]) AS CountOfStudentID
FROM [table of applicants] LEFT JOIN [Comments] ON [table of
applicants].[StudentID] = [Comments].[StudentID]
WHERE ((([Comments].[StudentID]) Is Null));

--
KARL DEWEY
Build a little - Test a little


KARL DEWEY said:
Try this editing it to your actual table and field names ---
SELECT Count([StudentID]) AS CountOfStudentID
FROM [table of applicants] LEFT JOIN [Comments] ON [table of
applicants].[StudentID] = [Comments].[Comment]
WHERE ((([Comments].[Comment]) Is Null));

--
KARL DEWEY
Build a little - Test a little


:

I have created a database of students who are attending our summer
program.
I have a form, based on the table of applicants, that has a subform
attached
where staff members can enter comments. The subform is linked to it's
own
table. I would like to count the number of applicants that I have
comments
on. If I use the =Count(*), it counts every record. I have set up a
query
that counts the unique field, student ID, in the table. How can I
count the
number of unique student IDs that are in the subform table in a
report?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top