using dcount for multiple critera

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

How do I write an expression using dcount if I want two fields for my critera?

For example I want to count all my classes for history and that staff person.

Count for class = history and staff = Mr. Johnson.

My fields are class and staff and my table is courses.

I need to concatenate the fields.

Thanks.
 
How do I write an expression using dcount if I want two fields for my critera?

For example I want to count all my classes for history and that staff person.

Count for class = history and staff = Mr. Johnson.

My fields are class and staff and my table is courses.

I need to concatenate the fields.

Thanks.

You have posted to a Form's newsgroup, so I'll assume this is to be
done on a form.

DCount counts the number of values in your table, not necessarily the
number of Staff and Class in your form's record source.
To use DCount with your specific criteria, using and Unbound control
on your form:

=DCount("*","TableName","[Class] = 'History' and [Staff] = 'Mr.
Johnson'")

The above assume the datatype of Class and Staff is text, not number.

If there is a chance that the Staff name value might contain an
apostrophe, i.e. O'Connor, then use:

=DCount("*","TableName","[Class] = 'History' and [Staff] = """Mr.
O'Connor"""")
 
Back
Top