Ron,
I have set up a table and a form to test this. Here is what I have.
tblTimes with 3 fields, StartTime and EndTime, both date time fields with
format set to General Date time.
3rd field is BillingRate -- Number field as single.
On the form a text box each for start time and end time and billing rate
An unbound text box txtTotalTime -- Control source =
IIf(DateDiff("n",[StartTime],[EndTime]) Mod
60=0,DateDiff("h",[StartTime],[EndTime]),DateDiff("n",[StartTime],[EndTime])/60)
A text box txtTotalAmount -- Control source = [txtTotalTime]*[BillingRate]
When you change the billing rate, the TotalAmount recalculates.
Jeanette Cunningham
Jeanette Cunningham said:
Ron,
also please post the code that calculates hours and minutes, as you
mentioned previously.
I assume that the text box called txtBillableHours does show the correct
value for hours and minutes for each row of the subform?
Jeanette Cunningham
Jeanette Cunningham said:
Ron,
please post what you currently have for the control source for
txtBillableHours
Jeanette Cunningham
Jeanette,
I tried the first code you suggested and got an error. If I use just
=[txtBillableHours] I get a number of hours, but they are totally wrong.
The
other code read error also. I guess that it's because [txtBillableHours]
contains a calculation. I don't know how to work around it. Thanks for
taking
your time to help.
:
Ron,
try
= Sum(Me.txtBillableHours)
Or
= Nz(Sum(Me.txtBillableHours)*Me.txtBillingRate, 0)
txtBillableHours is name of control for billable hours
txtBillingRate is name of control for billing rate
Replace above control names with your control names.
Jeanette Cunningham
Jeanette, thanks so much for your reply. I wil try to clarify this a
bit.
This is all on a subform. Billable Hours were manually input before.
I
added
Arrive Time and Depart Time because they wanted a record of this.
Then in
the
record source of the Billable Hours (txtBillableHours) I put the
HoursAndMinutes([DepartTime]-[ArriveTime]), so it would total on each
job.
Now I need to sum this in the form header so it can be used in other
areas. I
hope this gives you a better idea of what I am trying to do. I can't
get
anything to work. I tried: =Sum([txtBillableHours]*[BillingRate]),
but
couldn't get it to work. Thanks for any help.
:
Ron,
If you are on the parent form and want to know the value of a
control on
the
subform, use syntax like this
Me.[MainFormControl] =
Me.[NameOfSubformControlOnMainForm].Form.[ControlNameOnSubform]
Note that NameOfSubformControlOnMainForm is often different from the
name
of
the subform inside the subform control.
It looks like you need to create the sum of hours and minutes on the
subform
Use an unbound text box called txtTheSum with control source =
Sum([NameOfHrsAndMinsControl])
I assume that [BillingRate] is a field or control on the main form?
Back on the main form
= Me.Nz([NameOfSubformControlOnMainForm].Form.txtTheSum,
0)*[BillingRate]
Jeanette Cunningham
Although I have read the posts on this, I still can't get it to
work. I
have
put the following code into the subform control's record source:
HoursAndMinutes([DepartTime]-[ArriveTime]). The "HoursAndMinutes"
is
code
in
the module. It converts the time to hours and minutes. This works
on
the
form. I need to sum this in the forms header and multiply it times
the
billing rate. I have tried:
=Sum(HoursAndMinutes([DepartTime]-[ArriveTime]))*[BillingRate].
What do
I
need to do? Thanks