counting codes in a field

pascal

isolation
Local time
Today, 19:09
Joined
Feb 21, 2002
Messages
62
I made a form with a subform. On the subform, which is in datasheet view, I have a field called "Code". There are 4 codes (A,O,P,U). On the form I want to put a field that counts all the codes "A" that appear on the subform and not from the whole table underneath. How can I do this? I already tried several things but I always become the result of the codes "A" from the whole table.
Thank you for your help.
 
Let s take an example.
I have a main form, based (for example) on Table1, which PK is: ID.
A subform based on Table2 which has ID as a foreign key (one to many relationship between table1 and table2). So, the subform is linked to the main through parent/child field: ID.

I have a textbox bound to ID on the subform , eventually invisible (just to have the current value for the 'linking' field on hand).

I can use a simple Dcount, with the ID value as a criteria:
Dcount ("*", "Table2", "[ID] = " & Me.ID)

Alex

[This message has been edited by Alexandre (edited 02-22-2002).]
 
Thank you very much for you reply, Alexandre, but I still can't solve my problem. I'm going to specify my problem a bit more.

So, I've made a form with a subform, the subform is in datasheet view. The form and the subform are linked through an ID-number. On the subform I have a field (Combo box) called "Code" which can contain the following possibilities : A, O, P, U. I haven't made a table for these codes, I've put them in the row source in the table. Now, on the master form I want to put 4 text boxes. The first text box must count how much A-codes there are in the subform. The second text box must count how much O-codes there are in the subform and so on. And of course this must be updated immediately when a new record is entered in the subform.

Thank you very much for your help.
 
You'll have to do the calculations in the subform footer and refer to them on the main form, ie.Sum(Iif(
Code:
="A",1,0))and so on
 

Users who are viewing this thread

Back
Top Bottom