Link to home
Start Free TrialLog in
Avatar of Gian Reba
Gian Reba

asked on

I am working on a project management and would like to track the time spent on project task.

There is anybody out there who can help me to make this working ?, I'm a hobby developer , working on a project management and would like to track the time spendt on project task.
I would really appreciate if someone adept in coding could tell me why this isn't working when placed within a form, but works when in its own form, and how to make it work embedded in my form.  All it does now is when you click [btnStartTime] the [lblTime] displays 00:00:01, and keeps flickering at the currect interval as if it should be counting, but its not changing at all.  The [btnStopTime] works, at least the flickering stops, so that tells me its stoping the cycles even if the time isn't acutally changing.  and [btnResetTime] sets [lblTime] to 00:00:00 as it should.

Thank you in advance for all your assistance.
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

There seems to be information missing from your question. But my guess is you have a timer event running, and that timer event keeps resetting the time.

I prefer to avoid timer events if I can, and instead I suggest recording the starttime, and the endtime, and then calculate time spent.
While generally I agree with Anders Ebro answer, if you want a more concrete answer, please provide the code you are using.
Avatar of Gian Reba
Gian Reba

ASKER

Thank you for your suggestion, as I told I'm a hobby developer. Sorry I tought I had uploaded the SB.
Here is the attachment :)
SB.accdb
The form StopWatch (Working Example), works fine ;-)
Where are you having trouble?
Assuming you're referring to the Call Details form:

You're resetting the value of lngNumOfSecs (along with all your other variables) each time the Form_Timer event is called.

You need to move those to the General Declarations section at the top of your form module (just below the Option Explicit line), and comment out (or remove) this line in the btnResetTime_Click event:

Dim lngNumOfSecs As Long

Also - when posting a question you should use a descriptive title.  Using something like "Hello" would cause many Experts to assume this is spam, and they'll never look at it.
Hi again, I'm sorry for  the wrong title for my first posting. I'm quite new  using this kind of forum. I've tried to change the title but  couldn't find out of that.
Any way thank you for your interest on my problem, unfortunately I've been tried to make the suggested change , but I can't make it working.
I will appreciate any others suggestions about a kind of timer for tracking the time I spend om my project and task, I like the ' Call Detais form' as a  base for building my application.   Again thank you for your attention.
The code on the Call Details form should be:
Option Explicit
Private lngNumOfSecs As Long

Private Sub btnEnd_Click()
    Me.[End Time] = Now()
End Sub
Private Sub btnStart_Click()
    Me.[Start Time] = Now()
End Sub
Private Sub btnResetTime_Click()
    Me.TimerInterval = 0
    Me![lblTime].Caption = "00:00:00"
    lngNumOfSecs = 0
End Sub
Private Sub btnStartTime_Click()
    Me.TimerInterval = 1000
End Sub
Private Sub btnStopTime_Click()
    Me.TimerInterval = 0
End Sub
Sub cboCompanyName_AfterUpdate()
    'cboClientName.Requery
    'cboClientName = Null
    'cboScreenName = Null
    Me.PerCallCharge.RowSource = "SELECT [Per Call Charge], pkCompanyID FROM tblCompanyInfo WHERE ((([cboCompanyName]) Is Null Or ([cboCompanyName])=[pkCompanyID])) ORDER BY [Per Call Charge]"
    If Me.PerCallCharge.ListCount = 1 Then
        Me.PerCallCharge.Value = Me.PerCallCharge.ItemData(0)
    Else
        Me.PerCallCharge = Null
    End If
    Me.PerMinuteCharge.RowSource = "SELECT [Per Minute Charge], pkCompanyID FROM tblCompanyInfo WHERE ((([cboCompanyName]) Is Null Or ([cboCompanyName])=[pkCompanyID])) ORDER BY [Per Minute Charge]"
    If Me.PerMinuteCharge.ListCount = 1 Then
        Me.PerMinuteCharge.Value = Me.PerMinuteCharge.ItemData(0)
    Else
        Me.PerMinuteCharge = Null
    End If
    '    Me.cboScreenName.RowSource = "SELECT pkClientID, [Screen Name], fkCompanyID FROM qryClientExtended WHERE ((([cboCompanyName]) Is Null Or ([cboCompanyName])=[fkCompanyID])) ORDER BY [Screen Name]"
    Me.cboClientName.RowSource = "SELECT pkClientID, [Client Name], fkCompanyID FROM qryClientExtended" _
        & " WHERE  [fkCompanyID]='" & Nz(Me.cboCompanyName, fkCompanyID) & "'  ORDER BY [Client Name]"
    Me.cboScreenName.RowSource = "SELECT pkClientID, [Screen Name], fkCompanyID FROM qryClientExtended" _
        & " WHERE [fkCompanyID]='" & Nz(Me.cboCompanyName, fkCompanyID) & "' ORDER BY [Screen Name]"
    
End Sub
Private Sub cboClientName_AfterUpdate()
    'cboScreenName.Requery
    '    cboScreenName = Null
    Me.cboScreenName.RowSource = "SELECT pkClientID, [Screen Name], [Client Name] FROM qryClientExtended" _
        & " WHERE [Client Name]='" & Me.[cboClientName].Column(1) & "' ORDER BY [Screen Name]"
    If Me.cboScreenName.ListCount = 1 Then
        Me.cboScreenName.Value = Me.cboScreenName.ItemData(0)
    Else
        Me.cboScreenName = Null
    End If
End Sub
Private Sub cboScreenName_AfterUpdate()
    Me.cboClientName.RowSource = "SELECT pkClientID, [Client Name], [Screen Name] FROM qryClientExtended" _
        & " WHERE [Screen Name]='" & Me.cboScreenName.Column(1) & "' ORDER BY [Client Name]"
    If Me.cboClientName.ListCount = 1 Then
        Me.cboClientName.Value = Me.cboClientName.ItemData(0)
    Else
        Me.cboClientName = Null
    End If
    Me.txtClientNotes = Nz(DLookup("[Client Notes]", "tblClientInfo", "[Screen Name]=" & " & Me.cboScreenName & "))
End Sub

Private Sub cmdSaveandNew_Click()
    Dim strSQL As String
    Dim rs As Object
    Me.Refresh
    
    strSQL = "SELECT * FROM tblCallDetails WHERE pkCallID = " & Me.pkCallID
    Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
    If rs.RecordCount = 0 Then
        MsgBox "No record found"
        Exit Sub
    End If
    
    rs.Edit
    rs![Net Earnings] = Me.CallEarnings
    rs![Gross Earnings] = Me.Gross
    rs![Total Time] = Me.TotalTime
    rs![Taxes] = Me.Taxes
    rs![Company Charges] = Me.TotalCost
    ' Etcetera
    rs.Update
    Set rs = Nothing
    DoCmd.GoToRecord , , acNewRec
    Me.cboScreenName = ""
End Sub

Private Sub Form_Timer()
    Dim lngNumOfHrs As Long
    Dim lngNumOfMins As Long
    Dim lngNumOfSecsRem As Long
    
    lngNumOfSecs = lngNumOfSecs + 1
    
    Select Case lngNumOfSecs
    Case Is > 86400        '>1 day - not equipped for that
    Case Is >= 3600        '>1 hour
        lngNumOfHrs = lngNumOfSecs \ 3600
        lngNumOfMins = ((lngNumOfSecs - (lngNumOfHrs * 3600)) \ 60)
        lngNumOfSecsRem = lngNumOfSecs - ((lngNumOfHrs * 3600) + (lngNumOfMins * 60))
    Case Is >= 60          '>1 minute
        lngNumOfMins = ((lngNumOfSecs - (lngNumOfHrs * 3600)) \ 60)
        lngNumOfSecsRem = lngNumOfSecs - ((lngNumOfHrs * 3600) + (lngNumOfMins * 60))
    Case Is > 0            '< 1 minute
        lngNumOfSecsRem = lngNumOfSecs - ((lngNumOfHrs * 3600) + (lngNumOfMins * 60))
    Case Else              'shouldn't happen, but who knows?
    End Select
    
    Me![lblTime].Caption = Format$(lngNumOfHrs, "00") & ":" & Format$(lngNumOfMins, "00") & _
        ":" & Format$(lngNumOfSecsRem, "00")
End Sub

Open in new window

Thank You, MacroShadow.
Have you any idea why the field 'TotalTime' doesn't  update , after pressing 'Stop' button.
I'm very grateful for all help.
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wonderful, again thank you :)