Displaying result of Count on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
first sorry for this question but I am an access newbie....

I have a problem. I have a form with list of classes at a language school. I
have a table name people. I need to display the number of people that are
visiting the exact one class and I really don't know how.

I made a querry with something like this

SELECT Count(people.id) AS CountOfid
FROM people
WHERE people.kurz=classes.id;

When run this query, it askes me what class id it should count. So when i
put 1 in it, i will get the result. But I need to see this number in a form
field, when the form is showing the continuous list of classes.

Can anybody help me please?
 
Hi Kosik,

Try the following as the data source in your field:

=DCount("ID","People","kurz = " & ID)

But, replace the last ID with whatever the control name
is on your form that contains the ID number you are
trying to limit the domain to in your DCount function.

Post back if that doesn't work.

-Ted Allen
 
Hi Ted,
thanx a lot, it works, only with one problem. The result number is correct
but it is only shown when I click in the field, not when the form is loaded.
And again when I click somewhere else, the number disapers again. I also
tried to put the same thing in the starting data source (sorry for
translation, I have the czech version of access, so it is the third line
under data source), but it still doesn't work.

Petr

Ted Allen píše:
 
Hmm, I'm not familiar with the Czech version, but in the
US version I put the formula directly in the fields
control source (where you would normally choose a field
name if it were a standard bound control). But, when
doing this it is important to put the = sign in front of
the formula.

When I do this, the formula will generally display
always. By the way, I often put the formula inside of
the Nz() function to handle cases that are null.

If you have entered the formula as above, and it still
only shows when you click on the control, you may want to
try moving the field to the form header or footer to see
if that makes a difference. If not, you may want to use
the form's "On Current" event to assign the value
directly. In that case, you would add an unbound field
to the form, name it what you want (say txtStudentCount)
and then put something like the following in the On
Current event:

Me.txtStudentCount = DCount("ID","People","kurz = " &
Me.ID)

Hopefully one of those ideas will work for you. If not,
you may want to do a new post on the subject of a
calculated field only displaying when clicked. There may
be some other issue that I'm not aware of that could
cause this.

Hope that helps.

-Ted Allen
 
Hi Allen,
i tried to put the field in the header... doesn't work. And I also made the
event with Me.txt....... but i can't find the On Current filed in the events
of the field. Where is it, the first field I have in the Event properties is
BeforeUpdate but I can't find OnCurrent anywhere. Sorry for this silly
question, but there is also the problem that I have the czech version. Can
you please let me know where can I find the OnCurrent.

Thank you very much!

Petr

Ted Allen píše:
 
I assume that you found that the On Current event is a
form event, it sounds like you may have originally been
looking at the field events.

Post the code that you have in the On Current event, and
let me know what error message it is giving you and I'll
see if I can spot anything.

-Ted Allen
 
Back
Top