I apologize for making a gross mistake. Let's start over
with this.
The first rule of using aggregate functions is that they
only work with fields in the (sub)form/report's record
source table/query. This implies that the aggregate
functions are unaware of controls, (I ignored this earlier).
This means that the txtResults text box must be in the
subform's header or footer section, not in the main form.
Leave the txtEnterDate text box in the main form.
Note: do not confuse fields in a table/query with the
form/report controls that are used to display values. You
have explained the names of the controls, but not the names
of the fields they are bound to, so for now I will use
fldTherapyDate and fldPT to distinguish the fields from your
text box controls.
With that in mind, we have to find a way to write an
expression that does not refer to any text box controls.
Since you need to compare the value in a field to the value
in a control, we will need to create a public function in a
standard module to do the comparison. Here's an air code
example:
Public Function ChkRange(dt As Date, num As Variant) As
Variant
If dt >= Forms!theform.txtEnterDate - 6 _
And dt <= Forms!theform.txtEnterDate _
Then ChkRange = num
End Function
Once that is in place, the txtResults text box (in the
subform) can use the expression:
=Sum(ChkRange(fldTherapyDate, fldPT))
Next, we have to deal with the issue of getting the
expression to be re-evaluated whenever a user changes the
value in the txtEnterDate text box. This can be done by
adding a line of code to the txtEnterDate text box's
AfterUpdate event procedure:
Me.Recalc
Good luck unraveling all that,
--
Marsh
MVP [MS Access]
Expression: =Sum(IIf([txtEnterDate] Between [TherapyDate]
And [TherapyDate]-6,[PT],0))
In foot of Main form I added two boxes. 1)txtEnterDate
2)txtResults. The above expression is in the Control
Source property of the txtResults text box.
The subform named tblTherapyMinutes has a Date txtbox named
"TherapyDate"; a text box named "PT" which holds numbers;
the table has 48 records with the Dates filled in in
succession. The PT field has numbers in some but not all
records. When user enters a specific date they want to sum
any figures from that date back 6 days in the PT field.