COUNT function in a form

  • Thread starter Thread starter Majeed
  • Start date Start date
M

Majeed

I need to put a value of a COUNT funtion in a form, to no avail.
I have a field in a table titled RSLT. The values enetered are W, L or D. I
simply want to count how many D's or L's in a textbox in a Form.
In the form when i insert the following in the Record source :
=count ([RSLT])
I get all the records, but how to get D's only is beyond me.
I tried COUNTIF , but I got errors.

Thanks
 
Thanks..I appreciate that.



AJ Raiber said:
I would use the following piece of code in the
Form_AfterUpdate event.

Private Sub CountResults()

Dim intW As Integer
Dim intL As Integer
Dim intD As Integer
Dim db As Database
Dim recset As Recordset

Set db = CurrentDb()
Set recset = db.OpenRecordset("tblMyTable")

recset.MoveFirst

Do Until EOF

If rslt.Value = "W" Then
intW = intW + 1
ElseIf rslt.Value = "L" Then
intL = intL + 1
ElseIf rslt.Value = "D" Then
intD = intD + 1
End If

Loop

fldRSLTW = intW
fldRSLTL = intL
fldRSLTD = intD

recset.close

End Sub

Obvioulsy you will need to rename the fields in the bottom
and the table at the top, but this will update your counts
everytime you update a record.

HTH


-----Original Message-----
I need to put a value of a COUNT funtion in a form, to no avail.
I have a field in a table titled RSLT. The values enetered are W, L or D. I
simply want to count how many D's or L's in a textbox in a Form.
In the form when i insert the following in the Record source :
=count ([RSLT])
I get all the records, but how to get D's only is beyond me.
I tried COUNTIF , but I got errors.

Thanks


.
 
Back
Top