Count funtion on a control source

  • Thread starter Thread starter kim
  • Start date Start date
K

kim

I am trying to have a ticker at the bottom of form that
will perform a count on separate fields in the table. For
this example, I am trying to do a count on the due_date
field where the due_date is equal to today's date. Not
having much luck. The closest I have come up with is
=Count("[Aalst]![Due Date] =date()") which still returns
#error. Any ideas would be greatly appreciated.
 
kim said:
I am trying to have a ticker at the bottom of form that
will perform a count on separate fields in the table. For
this example, I am trying to do a count on the due_date
field where the due_date is equal to today's date. Not
having much luck. The closest I have come up with is
=Count("[Aalst]![Due Date] =date()") which still returns
#error. Any ideas would be greatly appreciated.

You can do this by using the Sum() function on a conditional expression
involving a field in the form's recordsource. Like this:

=Abs(Sum([Due Date] = Date()))
 
-----Original Message-----
kim said:
I am trying to have a ticker at the bottom of form that
will perform a count on separate fields in the table. For
this example, I am trying to do a count on the due_date
field where the due_date is equal to today's date. Not
having much luck. The closest I have come up with is
=Count("[Aalst]![Due Date] =date()") which still returns
#error. Any ideas would be greatly appreciated.

You can do this by using the Sum() function on a conditional expression
involving a field in the form's recordsource. Like this:

=Abs(Sum([Due Date] = Date()))

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
I still get the error. Is this because this is my main
form that isn't linked to the other tables? The
expression builder for the control source shows me the
table. Or am I using the wrong type of field to do this?
I appreciate your help.
 
Kim said:
-----Original Message-----
kim said:
I am trying to have a ticker at the bottom of form that
will perform a count on separate fields in the table. For
this example, I am trying to do a count on the due_date
field where the due_date is equal to today's date. Not
having much luck. The closest I have come up with is
=Count("[Aalst]![Due Date] =date()") which still returns
#error. Any ideas would be greatly appreciated.

You can do this by using the Sum() function on a conditional
expression involving a field in the form's recordsource. Like this:

=Abs(Sum([Due Date] = Date()))
I still get the error. Is this because this is my main
form that isn't linked to the other tables?

Probably. You haven't told me anything about your main form, any
subforms involved, or the table(s) being used as recordsources, so it's
hard to say for certain. You can only use an expression like that in
the header or footer section of a bound form whose recordsource includes
the field in question. Is the [Due Date] field on a subform? If so,
you would normally put the text box on the subform, not the main form,
though you could do that and have a text box on the main form that
actually picks up its value from the text box on the subform. But
you'll have to tell me more about how you have this set up before I can
give you more detailed advice.
The
expression builder for the control source shows me the
table. Or am I using the wrong type of field to do this?

The expression builder will let you build lots of expressions that may
be valid in some context, but not in the context in which you're trying
to use them. It doesn't pay to rely too much on the expression builder,
I'm afraid. It doesn't know what you're trying to do. As far as it
being the wrong type of field: I can't say, since you didn't say
anything about field types, but right now I doubt that that is the
problem.

More information, please.
 
More information:

Access 2000
2 tables - governement & industrial.
Main form that is not tied to either table.
Two buttons that link to either the government forms or
the industrial forms.
Added a text box, entered the code specified in the
Control Source field for the text box.

Error comes back in the text box with #error.
 
Kim said:
More information:

Access 2000
2 tables - governement & industrial.
Main form that is not tied to either table.
Two buttons that link to either the government forms or
the industrial forms.
Added a text box, entered the code specified in the
Control Source field for the text box.

Error comes back in the text box with #error.

What is the name of the table containing the [Due Date] field? In the
absence of a recordsource containing that field, you can get a raw count
directly from the table using the DCount() function. In your original
question, you implied that the table is named "Aalst". If that's so,
you could have a text box with this controlsource:

=DCount("*", "Aalst", "[Due Date]=Date()")

This is a different approach from the one I originally proposed, which
was based on the assumption that the form's recordsource contained the
[Due Date] field.
 
Back
Top