That has made a figure show now, the only problem is the figures are wrong,
Doesn't tell me much. As far as I can tell, the calculations are what you provided. Remember, the results are NOT a time (hh:mm) - it is the number of hours (X.X hrs) between the times. Do not format them as time.
I will look at the calculations again to see why this is. But also the main problem is that all the records are showing the same figure (the form is set to continuous forms) and i need the figure to change for each one, the idea is that users can see what jobs are to be worked today and for how long and they can see how many hours are available to book. Because some jobs spread over more than one day, this has made the calculation complicated because i need to only show the hours that job is using for the day selected.
Is it better to put the calculation as an expression in the HoursToday textbox itself in order to get a different result for each record, or is this still possible with code?
Convert it to a function and enter the function in the query.
The function: (WARNING - this is air code!!)
Code:
Function CalcHrs(txtDate As Date, pSDate As Date, pEDate As Date, pSTime As Date, pETime As Date) As Single
'returns hours.... 9 or 8.45
If txtDate = pSDate Then
CalcHrs = (DateDiff("n", pSTime, pETime)) / 60
ElseIf txtDate > pSDate And txtDate < pEDate Then
CalcHrs = 8
ElseIf txtDate > pSDate And txtDate = pEDate Then
CalcHrs = (DateDiff("n", #9:00:00 AM#, pETime)) / 60
Else
CalcHrs = -1111 '<=this is to indicate an error
End If
'1) If Forms!JobDetails.TextDate matches the date in StartDate then
' I want the field to calculate EndTime minus StartTime
'2) If Forms!JobDetails.TextDate is after the date in StartDate AND before the date in EndDate then
' the value of the field should be 08.00....... or
'3) If Forms!JobDetails.TextDate is after the date in StartDate BUT equals the date in EndDate then
' the value should be the time difference between 09.00.00 and EndTime
End Function
To call it:
In a column in the query for the subform "JobDetails":
Hrs: CalcHrs(Me.Parent!TextDate, StartDate, EndDate, StartTime, EndTime)
OR
In the control source for a text box:
=CalcHrs(Me.Parent!TextDate, StartDate, EndDate, StartTime, EndTime)