Terry said:
I need to count the number of records returned in a continous form recordset
that meets a certain condition. A bit like DCount but the domain needs to be
the RecodsetClone. How can I do this assuming that any code will be placed
in the OnCurrent event?
Since you want to do this in the Current event, I assume
your condition will depend on a value in the current record.
Unfortunately, as you've probably found out already,
aggregate functions are unaware of controls on a form or
report. This means you have to go a little round about to
calculate that. Without iterating through all the records
in the form's RecordsetClone, I can think of two ways to go
about it. One is to filter the form's data:
Dim rs As Recordset
With Me.RecordsetClone
.Filter = "somefield = " & Me.sometextbox
Set rs = .OpenRecordset()
End With
With rs
.MoveLast
Me.resulttextbox = .RecordCount
.Close: Set rs = Nothing
End With
The other way is to construct an expression with an
aggregate function and stuff it into the results text box's
Control Source:
Me.resulttextbox.ControlSource = _
"=Abs(Sum("somefield = " & Me.sometextbox & "))"