[RESOLVED] Trouble adding hours in data report
I have a data report in VB6 that has a function control on it used to display time on the report. In the details section of the report there is a field named 'DailyTime'. In the footer section, the function control is set to give the SUM of the 'DailyTime' field. This function control has a TIME format of hh:mm. This function control works fine as long as the total time does not exceed 23 hours. But here is my problem, the time will add up to over 150 hours. What do i need to do in the footer section of my report to get the total hours and minutes to display correctly?
I have tried giving the control a format of hhh:mm, but this does not work.
The report treats the 'hhh' as 'hh and h'.
For example...
if the time is supposed to be 7 hours, it gives 077
if the time is supposed to be 14 hours, it gives 1414
I also attempted to use the code window for the report, but you can't reference any report controls in the reports code.
Besides this, there is no way of writting code and haveing it execute on every cycle of the detail section of a report.
There really needs to be a way to format the function control in the footer section of the report so that it will display hours and minutes in excess of 23 hours.
Does anyone have any idea how I can overcome this problem?
Any help will be greatly appreciated !!
Re: Trouble adding hours in data report
What datatype is the DailyTime field?
Re: Trouble adding hours in data report
There are two other fields in the recordset: BeginTime and EndTime.
Both of which are of data type 'adDate'.
These two fields are pulled straight from a database table.
When writing the SQL to pull records from the database, i added the following line in the SELECT statement to get the DailyTime field:
(tblHours.EndTime - tblHours.BeginTime) AS DailyTime
According to what is in the Data Environment window, the data type of the DailyTime field is 'adDouble'.
Re: Trouble adding hours in data report
To properly format the number of hours and minutes between two dates you would need to use something like
Get the difference in hours
Get the difference in minutes and subtract total minutes used by the hours.
Format & Concatenate the two values into a string
VB Code:
strDisplay = Format$(DateDiff("h", BeginTime, EndTime), "00") & ":" & _
Format$(DateDiff("n", BeginTime, EndTime) - (DateDiff("h", BeginTime, EndTime) * 60), "00")
Re: Trouble adding hours in data report
Thanks... I will try this and let you know how it works for me...