VBA Form - Need Button - Time - Start & pause

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,284
Office Version
  1. 365
Platform
  1. Windows
Dear All

Is it possible to do start and pause the time on VBA Form..?

For example,
I have select any activity type from Combo box 1.

Time start in Text box.

after half an hour, user wants to take a break. Here, user can click a button say, "Pause". It will stop that time, and if he selects break option then break option text box time will start..

When again resume from break, user will stop the break time and will start the activity which he placed in "pause"

Can anyone please suggest on this...
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
You wouldn't pause, you'd start and stop.

a modular variable of total elapsed time,mvElapsed,
A local var to hold the start time at Click start,
VStart = now(),

at Stop, calc elapsed time in minutes:
mvElapsed= mvElapsed + DateDiff("n",vStart,Now())

At the end of work, post the elapsed time to a table
 
Upvote 0
Thanks for your reply..

But, it will helpful for me, only if code provide..
 
Upvote 0
.
Paste into a UserForm that has 1 Label and 2 Command Buttons :

Code:
Option Explicit


Private Sub BtnRaz_Click()
    mTimer2.TimerOff
    LblTemps.Caption = "00:00:00"


    With TButton1
        .Caption = "Start"
        .ForeColor = &H8000&
        .Value = False
    End With
End Sub


Private Sub TButton1_Click()
    With TButton1
        If .Value = True Then
            .Caption = "Stop"
            .ForeColor = &H80&
            mTimer2.TimerOn 1000
        Else
            .Caption = "Start"
            .ForeColor = &H8000&
            mTimer2.TimerOff
        End If
    End With
End Sub


Private Sub UserForm_Initialize()
    With TButton1
        .Caption = "Start"
        .ForeColor = &H8000&
        .Value = False
    End With
End Sub


Private Sub UserForm_Terminate()
    mTimer2.TimerOff
    Unload Me
End Sub

Download workbook : https://www.amazon.com/clouddrive/share/a8s89fz643VAb5X50lxdDShgC8nujn33xicZ0VMxwEe

There are three examples of a Timer In A Form. You want to look at Chrono 2
 
Upvote 0
Hi Logit,
This is something absolutly great for me. Super Fantastic...share...Thank You so much..!!

Some points here, I want to discuss here..

1. 1st of all, i really dont understand the code. I will see, and try to learn slowly slowly whenever I will get a time.

2. Logit, a sincere request. I have download the excel. On the 1st button, I like to go with that and use in my form. Only the micro seconds i dont want want in that. Can you please make change please.

But having said this, I really dont understand, how do i get the time..??
For example, I start with case 1. The moment when I will copy paste my case ID, timer will start. I will use this command button 1 code in my Text box click event.
But, suppose I want to go to break or meeting, then I need a pause button, which will stop the clock / time. And, the another time will start in Text box 2, for such non-core activities (break and all).

When I will return from my break, I will again click on say start button Or pause button, my clock will start from last point where i was stopped.

3. Logit, I dont understand that you said, above code you given, paste it into in form code..Why..?


Request you please answer me..

Please possible, solve my question no. 2 answer.

Many Thanks..
 
Upvote 0
Hi Logit, Im sorry, I have not checked properly your 2nd button. It is exactly what I want..

Only please guide me, I have 2 button on my form.

1 is for "Submit" button. if user done entire case ID, then he/she will click on "Submit" button. So the time taken will captured.

2 is for "Pending" button. if user unable to finish with that case ID, due to any reason Or query, then user will click use "Pending" button in that case. That time also time taken will captured.



The main purpose of this question is, I am creating a user form called timesheet tracker. Where user will start his / her day with cases assigned to them by Manager. To count how much time taken from every user for every case ID that should calculate...for this reason I want.
 
Upvote 0
.
For your needs, use the CHRONO 2 button only. That will give you the hours, minutes and seconds WITHOUT the micro-seconds.

The START button, when clicked, turns into a STOP button. What it really does is PAUSE the timer. So ...

Click the START button - the timer starts and the button says STOP .... when you want to pause the timer, click the STOP button and it turns to START. When you want to start the timer again to accumulate more time
in the same "run time" click the START button again.

The CLEAR button clears EVERYTHING from the timer and you have to start all over again from ZERO time.


You do not have to copy and paste anything if you don't want to. Just use the workbook as is. You can always delete the Command Buttons CHRONO1 and CHRONO 3 from the form if you
don't want to use those. You can delete the macro code tied to those buttons as well, leaving only the CHRONO 2 button and the code tied to that button.
 
Upvote 0
.
Reference your Post #6 ... if the user clicks either button (SUBMIT or PENDING), where does the total time from the User Form go ?

What cell or cells for each button ?
 
Upvote 0
Hi logit,
Again Thanks for attending my query. Appreciated.


.
Reference your Post #6 ... if the user clicks either button (SUBMIT or PENDING), where does the total time from the User Form go ?

Answer =
Logit, Submit here means, suppose I pick up one case.

A case is nothing but the task assigned to me by manager.

1. if i started my day with any case, and finish it within 1 hour suppose without taking any break, then it wont problem for us to capture my TAT to complete that task.

TAT = Turn around time.

2. Another scenario, i pick up the case, started my work, after an hour i want to take break. I will pause my time.**

When I come back I will again click on pause and my time start with what I have left.

** note - in 2 no. point it is possible now to pause and start b'coz you have provided excellent vba code and trick.
But, my time will start only when i paste my case id in Textbox1. Not by clicking on "CHRONO 2" button.

I will use "CHRONO 2" button only for pause purpose.

Now, consider that the case task is over after another one hour and then i clicked on "Submit" button. That time this clock time will go to backend and save.

Here, it is possible, that while performing this case, it go for pending scenario too. So when user decide to put the case in pending state and submit it will go to backend and save the clock time..

I hope and believe, I will get what I try to explain..


What cell or cells for each button ?
= I dont get this question.


Logit, request you please solve the query..Many Thanks..
 
Upvote 0
.
Thank you for your patience.

The information provided to you so far .... do you have everything you require to continue with your project ?

If the answer is "No" ... what additional information do you need ?
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top