Here are two days' boxes:
Sunday time text boxes:
Start Time:
Name: SunStartW1, Control Source: SunStartW1
End Time:
Name: SunEndW1, Control Source: SunEndW1
Calculation text box at bottom of Day:
Name: Text8,
Control Source: =(DateDiff("n",[SunStartW1],[SunEndW1])-30)/60
=============
Monday time text boxes:
Start Time:
Name: MonStartW1, Control Source: MonStartW1
End Time:
Name: MonEndW1, Control Source: MonEndW1
Calculation text box at bottom of Day:
Name: Text6,
Control Source: =(DateDiff("n",[MonStartW1],[MonEndW1])-30)/60
================
The goal is to get the two total times for the two days, which your DateDiff
calculation does correctly, to add the total of the two days together for a
total of hours worked.
I hope this helps.
Ron
Marshall Barton said:
You asked about assigning the hours to a variable, my
response was that "you can not reliably use the values from
calculated controls in VBA code". Note the part about
calculated controls and VBA code. Those are two different
environments that run in different code "threads". Both
environments are reliable, but mixing the two is not. Maybe
all this confision is caused by me applying specific
technical meaning to your vague general terminolgy, I can't
tell how precisely you are using these words.
txtMonHrs is the name name I made up for the text box
**control** (not variable) that calculates the Monday hours.
Ron wrote:
The only place I have the number of hrs for the day is in the calculated text
box that has the DateDiff function in it. But you say I can't rely on a
calculated box.
So I am confused as to what the =txtMonHrs is referring to.
:
Shouldn't be a problem doing that in a text box, but you can
not reliably use the values from calculated controls in VBA
code. Can't you get by with another text box expression
like:
=txtMonHrs + txtTueHrs + txtWedHrs + . . .
Ron wrote:
I have one additional challenge: Now I need to add the total hrs. worked
each day along the bottom, which is in the function you gave me.
I am having trouble assigning that value to a variable so I can add them up
for the 7 days. Suggestions?
:
The calculation is correct, but you are trying to use a time
format on a floating point number not a date/time value. If
you get rid of the text box's Format property, it should
display the correct number of hours.
Ron wrote:
VARIABLES:
MonStartW1 = 8:00 AM
MonEndW1 = 5:30 PM So: MonStartW1- MonEndW1 = 9:30
When I put your suggestion:
=(DateDiff("n",[MonStartW1],[MonEndW1])-30)/60 into my field, it returned
"0:00".
Ron wrote:
I have a vStartTime and an vEndTime. I want to subtract one from the other,
and then subtract 30 minutes unpaid time for lunch to see how many total
hours a person worked in a day.
I have tried unsuccessfully to use many variations of the =DateDiff function.
:
I think this expression would do that:
(DateDiff("n", vStartTime, vEndTime) - 30) / 60