473,413 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

calculate grand total time in continuous forms

I need help to make grand total time in continuous forms.
to calculate total work time I use following formula
=format([timeout]+1-[timein]-nz([lunch]);"short time").
but when I make grand total time in form footer (for all records) my result is error.
My grand total must be in format [hh:mm].
thanks,
Nov 14 '06 #1
17 11178
Killer42
8,435 Expert 8TB
=format([timeout]+1-[timein]-nz([lunch]) ; "short time")
Can you just check something for me? I'm not certain, but I think the semicolon should be a comma.
Nov 14 '06 #2
NeoPa
32,556 Expert Mod 16PB
The Format() function returns a string value.
It doesn't matter that the characters in the string look like it may be a number - Access is not fooled.
You can't perform arithmetic of any sort on a string.

Rather than using the Format() function, try using the Format property of the TextBox instead.
Nov 14 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
I need help to make grand total time in continuous forms.
to calculate total work time I use following formula
=format([timeout]+1-[timein]-nz([lunch]);"short time").
but when I make grand total time in form footer (for all records) my result is error.
My grand total must be in format [hh:mm].
thanks,
Using this formula given the values below
= Format(([timeout] + 1 - [timein] - nz([lunch],0), "short time").

'if lunch is one hour
= Format((#6:12:00 PM# + 1) - (#9:25:00 AM#) - Nz(#1:00:00 AM#, 0), "short time")
Result: 07:47:00

'if lunch is a null value
= Format((#6:12:00 PM# + 1) - (#9:25:00 AM#) - Nz(Null, 0), "short time")
Result: 08:47:00

Now to sum in the footer:

This is quite complicated.

Firstly you will need two textboxes in the footer. One to hold the sum of time called calcTime (set visible to "No") and the other to display the result called txtTotalTime. Don't set either of them to anything for the moment. This will have to be done using VBA code.

Next you need to put the following function in a module.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function totalTime(tTime As Double) As String
  3. Dim days As Integer
  4. Dim hours As Double
  5. Dim minutes As Integer
  6.  
  7.   days = Int(tTime)
  8.   Debug.Print days
  9.   hours = 24 * (tTime - days)
  10.   Debug.Print Int(hours)
  11.   minutes = (hours - Int(hours)) * 60
  12.   Debug.Print minutes
  13.  
  14.   totalTime = days & " days " & Int(hours) & " hrs " & minutes & " mins"
  15.  
  16. End Function
  17.  
  18.  
Now finally you will have to create an AfterUpdate function based on the control holding total work time value for each record on the main form.
For the example I'm calling it totalWorkTime as I don't know what you've named it.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub totalWorkTime_AfterUpdate()
  3. Dim ttltime As Double
  4.  
  5.   ' you first have to save the record that was just updated 
  6.   DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  7.  
  8.   ' get the total times  
  9.   Me.calcTime = DSum("TimeValue([DateFiled])", "tblFilingDates", "")
  10.   ttltime = Me.calcTime
  11.  
  12.   ' call the function to calculate days, hours and minutes
  13.   Me.txtTotalTime = totalTime(ttltime)
  14.  
  15. End Sub
  16.  
  17.  
You will also need to put in a form load event as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3. Dim ttltime As Double
  4.  
  5.   ' get the total times  
  6.   Me.calcTime = DSum("TimeValue([DateFiled])", "tblFilingDates", "")
  7.   ttltime = Me.calcTime
  8.  
  9.   ' call the function to calculate days, hours and minutes
  10.   Me.txtTotalTime = totalTime(ttltime)
  11.  
  12. End Sub
  13.  
  14.  
I said it was complicated. The problem is that you cannot calculate times over 24 hours which is why you need the function.
Nov 15 '06 #4
NeoPa
32,556 Expert Mod 16PB
Are you sure about this Mary?
Times, being a fraction of a day should work as any other number behind the scenes to my understanding.
Looks like I'll have to run some tests over my lunch ;).
I'll post my findings, but let me know if you think I've not understood something.
Nov 15 '06 #5
NeoPa
32,556 Expert Mod 16PB
I tried this with the Now() function originally but, for reproducibility of results I changed it to Date/time literals which are country independant.
Expand|Select|Wrap|Line Numbers
  1. ?Format(#15 Nov 12:37:33#,"d/m/yyyy hh:nn:ss"), Format(#15 Nov 2006 12:37:33#+#11:55:00#,"d/m/yyyy hh:nn:ss")
  2. 15/11/2006 12:37:33         16/11/2006 00:32:33
This indicates that Date/Time fields conform to standard arithmetic rules.
Nov 15 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
Are you sure about this Mary?
Times, being a fraction of a day should work as any other number behind the scenes to my understanding.
Looks like I'll have to run some tests over my lunch ;).
I'll post my findings, but let me know if you think I've not understood something.
That's not the problem. The problem is that if as I suspect only the time is being recorded then the date field can't be used in the arithmetic.

Therefore as the total time is being summed over all records in the form this would go over 24 hours and that cannot be handled with a specific format or any of the existing date functions.

The result returns a decimal number which needs the function I've included to break it out into days hours and mins.
Nov 15 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
I need help to make grand total time in continuous forms.
to calculate total work time I use following formula
=format([timeout]+1-[timein]-nz([lunch]);"short time").
but when I make grand total time in form footer (for all records) my result is error.
My grand total must be in format [hh:mm].
thanks,
Barkarlo

Just a note regarding this line in the code

Me.calcTime = DSum("TimeValue([DateFiled])", "tblFilingDates", "")

The field and table names here are from the test I ran. Change tblFilingDate to your own table name and [DateFiled] to the field in which you are storing the calculated Total_Hours value. If you are not storing that field you will need to for this to work. Otherwise let me know and I'll change the code accordingly.
Nov 15 '06 #8
NeoPa
32,556 Expert Mod 16PB
Mary,

You're right. I see what you mean about the days.
But the time element could be better formatted as :
Expand|Select|Wrap|Line Numbers
  1. Format(tTime, "h \hr\s n \mi\n\s")
...though now I test it out - it is a little kludgy - maybe your way's best after all.
Nov 15 '06 #9
MMcCarthy
14,534 Expert Mod 8TB
Mary,

You're right. I see what you mean about the days.
Don't you know by now I'm always right.



But the time element could be better formatted as :
Expand|Select|Wrap|Line Numbers
  1. Format(tTime, "h \hr\s n \mi\n\s")
...though now I test it out - it is a little kludgy - maybe your way's best after all.
Well DAWHHH!!!



Actually, I knew about the problem as I've come up against it before. Experience is a great teacher.

Mary
Nov 15 '06 #10
Barkarlo

Just a note regarding this line in the code

Me.calcTime = DSum("TimeValue([DateFiled])", "tblFilingDates", "")

The field and table names here are from the test I ran. Change tblFilingDate to your own table name and [DateFiled] to the field in which you are storing the calculated Total_Hours value. If you are not storing that field you will need to for this to work. Otherwise let me know and I'll change the code accordingly.
"worktime" is name for the field and that is stored in form.
I don't know where the field must be stored( in table or in form).
Nov 15 '06 #11
MMcCarthy
14,534 Expert Mod 8TB
"worktime" is name for the field and that is stored in form.
I don't know where the field must be stored( in table or in form).
No it's ok, it just changes the approach slightly.

Drop the calcTime field and replace the worktime after update event with the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub worktime_AfterUpdate()
  3. Dim ttltime As Double
  4. Dim rs As Recordset
  5.  
  6.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  7.     Set rs = Me.RecordsetClone
  8.     ttltime = 0
  9.  
  10.     rs.MoveFirst
  11.     Do Until rs.EOF
  12.         ttltime = ttltime + TimeValue(rs!worktime)
  13.         rs.MoveNext
  14.     Loop
  15.     Me.txtTotalTime = totalTime(ttltime)
  16.     rs.Close
  17.  
  18. End Sub
  19.  
  20.  
And change to Form load event to a form open event and use the following code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Open()
  3. Dim ttltime As Double
  4. Dim rs As Recordset
  5.  
  6.     Set rs = Me.RecordsetClone
  7.     ttltime = 0
  8.  
  9.     rs.MoveFirst
  10.     Do Until rs.EOF
  11.         ttltime = ttltime + TimeValue(rs!worktime)
  12.         rs.MoveNext
  13.     Loop
  14.     Me.txtTotalTime = totalTime(ttltime)
  15.     rs.Close
  16.  
  17. End Sub
  18.  
  19.  
Nov 15 '06 #12
No it's ok, it just changes the approach slightly.

Drop the calcTime field and replace the worktime after update event with the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub worktime_AfterUpdate()
  3. Dim ttltime As Double
  4. Dim rs As Recordset
  5.  
  6.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  7.     Set rs = Me.RecordsetClone
  8.     ttltime = 0
  9.  
  10.     rs.MoveFirst
  11.     Do Until rs.EOF
  12.         ttltime = ttltime + TimeValue(rs!worktime)
  13.         rs.MoveNext
  14.     Loop
  15.     Me.txtTotalTime = totalTime(ttltime)
  16.     rs.Close
  17.  
  18. End Sub
  19.  
  20.  
And change to Form load event to a form open event and use the following code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Open()
  3. Dim ttltime As Double
  4. Dim rs As Recordset
  5.  
  6.     Set rs = Me.RecordsetClone
  7.     ttltime = 0
  8.  
  9.     rs.MoveFirst
  10.     Do Until rs.EOF
  11.         ttltime = ttltime + TimeValue(rs!worktime)
  12.         rs.MoveNext
  13.     Loop
  14.     Me.txtTotalTime = totalTime(ttltime)
  15.     rs.Close
  16.  
  17. End Sub
  18.  
  19.  
Ok, let's go from the beginning.
I have a continuous form with following fields from the table "tblexploatation"
employees;date;beginningtime;endtime;timeout. I made new field "worktime" and use formula FORMAT([endtime]+1-[beginningtime]-nz([timeout];"short time").
Can you tell me which formula or function you use for that the field.
I made function totaltime and two text box in form footer ("totaltime", "grandtotaltime").
In the field "totaltime" I have put it code in after update event as in form open event ,but when I run this return me error in code "ttltime=ttltime+timevalue(rs!worktime)
what is this?
Nov 16 '06 #13
MMcCarthy
14,534 Expert Mod 8TB
continuous form from the table "tblexploatation"

tblexploatation
employees
date
beginningtime
endtime
timeout
worktime (new field in table with date/time data type and Short Time format)

OK

Now on the form for the control for the worktime field make sure the Control Source is set to worktime not FORMAT([endtime]+1-[beginningtime]-nz([timeout];"short time").

I made function totaltime and two text box in form footer ("totaltime", "grandtotaltime").
In the field "totaltime" I have put it code in after update event as in form open event ,but when I run this return me error in code "ttltime=ttltime+timevalue(rs!worktime)
what is this?
You were getting this error because worktime didn't actually exist in the table.

Keep grandtotaltime as a textbox and drop totaltime as a textbox but keep the function (in a separate module). Don't format grandtotaltime to a date/time or number as it will be a string.

Now forget the afterupdate event and set a command button on the form footer. For the example call it cmdCalc.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdCalc_Click()
  3. Dim ttltime As Double
  4. Dim rs As Recordset
  5.  
  6.   DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  7.   Set rs = Me.RecordsetClone
  8.   ttltime = 0
  9.  
  10.   rs.MoveFirst
  11.   Do Until rs.EOF
  12.     rs.Edit
  13.     rs!worktime=(([endtime]+1) - [beginningtime]) - nz([timeout],0)
  14.     rs.Update
  15.     ttltime = ttltime + rs!worktime
  16.     rs.MoveNext
  17.   Loop
  18.  
  19.   Me.grandtotaltime = totalTime(ttltime)
  20.  
  21.   rs.Close
  22.   Set rs=Nothing
  23.  
  24. End Sub
  25.  
  26.  
Nov 17 '06 #14
continuous form from the table "tblexploatation"

tblexploatation
employees
date
beginningtime
endtime
timeout
worktime (new field in table with date/time data type and Short Time format)

OK

Now on the form for the control for the worktime field make sure the Control Source is set to worktime not FORMAT([endtime]+1-[beginningtime]-nz([timeout];"short time").



You were getting this error because worktime didn't actually exist in the table.

Keep grandtotaltime as a textbox and drop totaltime as a textbox but keep the function (in a separate module). Don't format grandtotaltime to a date/time or number as it will be a string.

Now forget the afterupdate event and set a command button on the form footer. For the example call it cmdCalc.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdCalc_Click()
  3. Dim ttltime As Double
  4. Dim rs As Recordset
  5.  
  6.   DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  7.   Set rs = Me.RecordsetClone
  8.   ttltime = 0
  9.  
  10.   rs.MoveFirst
  11.   Do Until rs.EOF
  12.     rs.Edit
  13.     rs!worktime=(([endtime]+1) - [beginningtime]) - nz([timeout],0)
  14.     rs.Update
  15.     ttltime = ttltime + rs!worktime
  16.     rs.MoveNext
  17.   Loop
  18.  
  19.   Me.grandtotaltime = totalTime(ttltime)
  20.  
  21.   rs.Close
  22.   Set rs=Nothing
  23.  
  24. End Sub
  25.  
  26.  
The field "worktime" is in the form.
Nov 17 '06 #15
MMcCarthy
14,534 Expert Mod 8TB
The field "worktime" is in the form.
You can't sum on a calculated unbound control. You will have to add it to the table.
Nov 17 '06 #16
You can't sum on a calculated unbound control. You will have to add it to the table.
I tried with the function "hoursandminutes"

Expand|Select|Wrap|Line Numbers
  1. public function hoursandminutes(interval as variant) as string
  2. dim totalminutes as long, totalseconds as long
  3. dim hours as long,minutes as long, seconds as long
  4.  
  5.   if isnull(interval)=true then exit function
  6.  
  7.   hours=int(CSng(interval*24))
  8.   totalminutes=int(CSng(interval*1440))
  9.   minutes=totalminutes mod 60
  10.   totalseconds=Int(CSng(interval*86400))
  11.   seconds=totalseconds mod 60
  12.  
  13.   if seconds>30 then minutes=minutes+1
  14.   if minutes>59 then hours=hours+1
  15.   hoursandminutes=hours & ":" & format(minutes, "00")
  16.  
  17. end function
  18.  
  19.  
in form detail I made unbound control and put it following formula:
worktime=hoursandminutes([endtime]+1-[beginningtime]-nz([lunch])).
and in footer
totalworktime=hoursandminutes(sum([endtime]+1-[beginningtime]-nz([lunch]))).
Here is one problem! if sum hours exceeding 24 hours function returns me only hours more than 24.
for an example:
28:30 return 4:30
What to do to make the function return full time.
thanks for help me
Nov 18 '06 #17
Killer42
8,435 Expert 8TB
I tried with the function "hoursandminutes"
...
in form detail I made unbound control and put it following formula:
worktime=hoursandminutes([endtime]+1-[beginningtime]-nz([lunch])).
and in footer
totalworktime=hoursandminutes(sum([endtime]+1-[beginningtime]-nz([lunch]))).
Here is one problem! if sum hours exceeding 24 hours function returns me only hours more than 24.
for an example:
28:30 return 4:30
What to do to make the function return full time.
thanks for help me
Have you checked exactly what value is being received in your function? Your code is quite straightforward and should not "clock over" at 24 hours. But maybe the actual Sum() function (highlighted above) is returning the truncated value. I'd suggest you do a Debug.Print or something on entry to the function, and see what value was received.
Nov 19 '06 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
4
by: lyndsey | last post by:
i have a database to keep record of jobs in production, and on one of my forms, their is the control . in my form i have hundereds of records (jobs). is there a way i can create something in my...
6
by: Coleen | last post by:
Hi All :-) Thanks for all of your help Cor :-) I can not get the code you sent me to work in my application. I'm using an aspx datagrid in a web form. I'm getting the following error message...
4
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost...
0
by: jessicaeatworld | last post by:
Hi, I'm using Access 2003 on Windows XP. I have created a PivotTable View Form and at the bottom is an automatically inserted Grand Total row. I added sum and avg fields and then hid the details so...
0
by: Racqetsports | last post by:
Hi there, In a gradebook database, student grades must be computed from 2 scores: a Daily grade, and then scores from Assignments. Knowing about nested forms, I am requesting direction on how to...
5
by: Wiley | last post by:
I have created a form that contains 1000s of items, though I have an expression that have calculated the grand total. If I make any changes to my quantities the grand total does not change. Hence how...
4
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days...
2
by: Bytesmiths | last post by:
I'm using GROUP BY to come up with totals for some items, but would like to either have a grand total at the bottom, or a running total field. I tried to use a variable as I found in several...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.