Re: Calculate certain number of records



<<<<
? DCount("*", "MyTable", "MyField = 'abc'")


I got this to work in the Ctrl-G mode!

But I probably seem to be missing the obvious.
This is what I do:

I create an empty form
I put a textfield in it
I click right on it and then choose 'Building event' (translated from Dutch)
I paste the above text and when I close this window it tells me it's not a
correct expression. This also happens when i change the ? for a =.
What am I doing wrong?
john

"Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx> schreef in bericht
news:44ba3c09$0$23360$5a62ac22@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Since the value to be matcheds is text, I take it that MyField is a Text
field (not a Number field.)

Your 2nd exampls should work.

The * tells Access to count all fields where there is a match.

If it still fails, press Ctrl+G to open the Immediate window.
There type the expression an press enter:
? DCount("*", "MyTable")
That should give you the total number of records in the table.

Now try:
? DCount("*", "MyTable", "MyField = 'abc'")

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"john" <john@xxxxxxxx> wrote in message
news:78WdnTDbqOnCnSfZnZ2dnUVZ8qKdnZ2d@xxxxxxxxxxxx
Thanks, but I can't get it to work even after reading the explanation.
=DCount("*", "MyTable", "MyField = abc")
or
=DCount("*", "MyTable", "MyField = 'abc'")
are not accepted as an expression.
What does the * stand for in the expression, btw?

To make sure we're talking about the same thing. I want a field on my
form that has no relation with the current record. It should show the
number of records of the whole table where the value of MyField is abc.
john

"Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx> schreef in bericht
news:44b8b833$0$21733$5a62ac22@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
This kind of thing should work:
=DCount("*", "Table1", "ClientID = 99")

The arguments DCount() needs are the same as for DLookup(), so if you
are having difficulty supplying the 3rd one, see the explanation in this
article:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

"john" <john@xxxxxxxx> wrote in message
news:aqSdneDWqZ99AiXZnZ2dnUVZ8s2dnZ2d@xxxxxxxxxxxx
I have a form with 1 table. I would like to create a field in my form
that shows the number of records (of the whole table) that have one
particular value. Is that possible? I fiddled with a calculated field
but I couldn't make it work.
Thanks in advance,
john




.



Relevant Pages

  • Re: Calculate certain number of records
    ... I create an empty form ... press Ctrl+G to open the Immediate window. ... Getting a value from a table: DLookup() ...
    (comp.databases.ms-access)
  • Re: Calculate certain number of records
    ... I create an empty form ... press Ctrl+G to open the Immediate window. ... Getting a value from a table: DLookup() ...
    (comp.databases.ms-access)
  • Re: Calculate certain number of records
    ... Since the value to be matcheds is text, I take it that MyField is a Text ... Tips for Access users - http://allenbrowne.com/tips.html ... Getting a value from a table: DLookup() ...
    (comp.databases.ms-access)
  • Re: Lookup Field in form from subform
    ... Sorry about the confusion, off course it is the tables that have a ... I have tried Dlookup but the field then ... John Vinson wrote: ... >>a field in Form C and add it to a field in subform A. The to forms ...
    (microsoft.public.access.forms)
  • Re: A Need for Speed....
    ... Thanks, John, I think I've resolved this. ... The function doing the DLookup was returning a value that's already sitting ... "John W. Vinson" wrote: ... "gate x to y" comment string for the output. ...
    (microsoft.public.access.queries)