The age old Calculating Time question...

Elijahnzl

Registered User.
Local time
Today, 16:10
Joined
Oct 31, 2012
Messages
19
This is the code I am using

Code:
Private Sub cmd_Stop_Click()
    Finish.Value = Time()
    'Finish.Enabled = False
    Worked.SetFocus
    Worked.Value = DateDiff("n", [Start], [Finish])
    
    
    
    
    
End Sub
Private Sub Command10_Click()
    Start.Value = Time()
    'Start.Enabled = False

So, what I am trying to do is subtract my start time from my end time and give me answer [Worked] in hours and minutes.

Once I do this I need to be able to print a report on a weekly basis that totals the hours worked.

The above code returns a Date. Can someone please help me?

Regards
Gene
 
Your not giving much info here to support your code. Are the variables Finish and Worked part of a class file or are they Types and why not just store the value's in a table so you can have your report get the data from there?
 
Dear thechazm

As someone who has very little knowledge in Access VBA I do not understand some of what you are asking in regards to Class and/or Types.

I am using a Table: tbl_Timesheet. The form, frm_Timesheet, is based on this table.
The Table has fields: Start, Finish, Worked.
On the form I have two buttons - start and finish, three text boxes (named same as fields)
When the Start button is clicked the current time is placed into the Field: Start
When the Finish button is clicked the current time is placed into the Field: Finish

What I am trying to do is populate the Field: Worked with the difference between Finish and Start in hours:minutes. I am trying to do this when the Finish button is clicked.

I know of no other way to explain what I am doing - sorry if this isn't good enough. Perhaps someone else can help?
 
i would calculate the number of minutes between start and finish and then just tot them all up. easiest way would be to have 2 fields, 1 for hours and 1 for mins. something like...

worked = ((finish_hours - start_hours)*60) + (finish_mins - start_mins) / 60

start with a query selecting all records for 1 person with "sum" in the totals () put that answer in non-visible textboxes called "finish_hours" etc.
very basic, but it will do the job!
 
If you use the function called datediff it should give you your difference in whatever format that you want.
 

Users who are viewing this thread

Back
Top Bottom