Code problem, can anyone help?

wh00t

Registered User.
Local time
Today, 22:56
Joined
May 18, 2001
Messages
264
Greetings all

I have the following script from the Microsoft Knowledge base, but it is not working

Code:
      Function GetTimeCardTotal ()
         Dim db As Database, rs As Recordset
         Dim totalhours As Long, totalminutes As Long
         Dim days As Long, hours As Long, minutes As Long
         Dim interval As Variant, j As Integer

         Set db = dbengine.workspaces(0).databases(0)
         Set rs = db.OpenRecordset("timecard")
         interval = #12:00:00 AM#
            While Not rs.EOF
               interval = interval + rs![Daily hours]
               rs.MoveNext
            Wend
         totalhours = Int(CSng(interval * 24))
         totalminutes = Int(CSng(interval * 1440))
         hours = totalhours Mod 24
         minutes = totalminutes Mod 60

      GetTimeCardTotal = totalhours &" hours and " &minutes &" minutes"

      End Function

for starters the following line is incorrect
GetTimeCardTotal = totalhours &" hours and " &minutes &" minutes"

should be hours, not total hours

but the code is not working

I still get a result of 01 hours and 45 minutes, when according to this KBase document the result of 25 hours and 45 minutes should be displayed, I have followed the insctructions word by word, any help would be appreciated.

EDIT - the script calculates time (well according to the KBase doc calculates time)
e.g. 8:15 + 8:30 + 9:00 = 25:45

KBase Doc http://support.microsoft.com/default.aspx?scid=kb;en-us;Q88657

[This message has been edited by wh00t (edited 05-27-2002).]
 
Recreating your prob, I find that if you use TotalHours in the GetTimeCard line then it is fine. ie remove Hours=totalhours mod 24

HTH
 
Thanx for the reply, but when I do this, the following result is displayed
230337 hours and 45 minutes
 
sounds like your time field is also carrying dates. try cleaning the field up with (as an idea...not tested) interval = interval + rs("Dailyhours")-int(rs("Dailyhours")) That ought to remove any whole days associated with one of your times.
 
thats got it, thanks for the reply
 

Users who are viewing this thread

Back
Top Bottom