+ Reply to Thread
Results 1 to 22 of 22

Start / Pause timer Button

  1. #1
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Start / Pause timer Button

    I want to create 1 button with two function for my timer it should be like Start and Pause I' using userform.



    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by N323100; 07-19-2017 at 07:48 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Start / Pause timer Button

    Hi,

    The following code will pause timing. When PauseOrRestartTimer() is called a second time, the count will resume from the pause time. Slightly different logic is required to keep the timer running while the display is paused.
    Please Login or Register  to view this content.
    NOTE: For resolution to one hundredth of a second see Timer. http://www.excelfunctions.net/vba-timer-function.html


    Lewis

  3. #3
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    Thanks for the inputs.

    I attached the file and put the following codes accordingly, but its not working properly I'm not sure if I did it right?

    Thank you
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Start / Pause timer Button

    One small error.

    In the UserForm code module, you used 'StartTimer()', when 'StartStopWatch()' should have been used.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    Thank you this is a great help!
    Last edited by N323100; 07-20-2017 at 07:04 AM.

  6. #6
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    I have a follow up question. I want to trigger the StartStopWatch but completing to fillin' up the ComboBox6 but the only problem if the time that the user change the information in ComBobox6 the StartStopWatch will return to 00:00:01

    here are the details of my ComboBox

    Please Login or Register  to view this content.
    and also I have this code in submit button
    Please Login or Register  to view this content.
    but the textbox or time still running it doesn't remove in textbox. I tried to pause the time and click the submit button and the time in textbox was removed. maybe it should be stop the time first before it was cleared or removed in textbox?
    I would appreciate if there is a easy way to my dilemma.

    Thank you
    Last edited by N323100; 07-20-2017 at 10:02 AM.

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Start / Pause timer Button

    The following may help you. If not I will come up with a working example for you:
    a. StartStopWatch() should only be called when you want to start from 0:00.
    b. PauseOrRestartTimer() will 'pause' the 'stopwatch' if it is running. PauseOrRestartTimer() will make the 'stopwatch' continue from the value that is currently in the display, if it was 'paused'.

  8. #8
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    Yeah I'm using that code and it works perfectly. The only problem is I have a submit button that will transfer the data including the time into another sheet, once the submit button was click by the user all of the information in userform will be empty or delete to enter a new information again. but the time still shows up in textbox3 even I already put a code the delete or empty the textbox. Thank you for helping me with this project.

  9. #9
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Start / Pause timer Button

    The only problem is I have a submit button that will transfer the data including the time into another sheet, once the submit button was click by the user all of the information in userform will be empty or delete to enter a new information again. but the time still shows up in textbox3 even I already put a code the delete or empty the textbox.
    I need to see a sample file that demonstrates the problem. The symptoms suggest that data must be stored somewhere at the beginning of the 'Submit' routine, and then the data must be restored later.

  10. #10
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    I will upload the file....thanks

  11. #11
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    Please see attached file.. Please refer to Activity Tracker Userform. Thanks for patiently helping
    Attached Files Attached Files
    Last edited by N323100; 07-21-2017 at 08:59 AM.

  12. #12
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Start / Pause timer Button

    If I understand your question correctly, after you select 'Submit', you want TextBox3 to be blank.

    You cleared the contents of the TextBox, but you did not stop the timer first, so the timer continued to run, and kept updating the value in TextBox3. If you add the item in red below to the UserForm code, you will probably fix your problem:
    Please Login or Register  to view this content.
    Lewis

  13. #13
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    Hi Thanks you, I tried the above code but still the timer shows after the submit button.

  14. #14
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Start / Pause timer Button

    Sorry for the problem. When CommandButton4 (i.e. Submit) called MsgBox it Timer requests queued up, and caused StopTimer() to not work properly. StopTimer() must be the first command in UserForm code for CommandButton4_Click() (Submit) and also in CommandButton3_Click() (Reset/Close).

    The attached file implements those changes and hopefully will work the way you want.

    In the ActivityTracker UserForm code module:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by LJMetzger; 07-23-2017 at 04:39 PM.

  15. #15
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    This is perfect! Thank you for your BIG Help with this project.

    Now you see the userform for activity tracker I'm planning to remove the Start Time button and leave the Pause/Resume button, I want to start the time if the TextBox and ComboBox has a information on it, before a I tried to create that conditional but if there is a chance the a user change something on any of the textbox or combobox the Timer Restart to 0. Sorry if I make everything complicated
    Last edited by N323100; 07-24-2017 at 04:54 AM.

  16. #16
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Start / Pause timer Button

    It was my pleasure to help. When I have a lot of options like you have on the UserForm, I find the logic to be easier to control if I:
    a. Create separate CommandButtons for each task, instead of sharing.
    b. Create a separate Sub to Display or Hide CommandButtons as required.

    For example: When the UserForm is opened, the 'Start' CommandButton is visible and the 'Pause' CommandButton is not visible.
    When the timer starts, then the 'Start' CommandButton is not visible, and the 'Pause' CommandButton is visible.

  17. #17
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    Actually my plan is to removed the Start Button and put a conditional statement if all the corresponding textbox and combox is not empty the start will start thank you for all the help

  18. #18
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    Hi I got an issue again in emptying the Timer

    Reset Button under different UserForm.

    Please Login or Register  to view this content.
    Thank you,
    Last edited by N323100; 07-26-2017 at 09:24 AM.

  19. #19
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Start / Pause timer Button

    Hi,

    I can't see anything wrong with the code. My speculation is that there is something somewhere that says 'timer' instead of 'timer1'.

    Instead of creating multiple timers see the attached file which contains the following code changes in red, that should allow you to use the same timer code for all your UserForms.

    In the ThisWorkbook code module (to make sure the timer terminates properly):
    Please Login or Register  to view this content.
    In the ActivityTracker UserForm code module (to make sure the timer terminates properly):
    Please Login or Register  to view this content.
    In ordinary code module module2 (timer code):
    Please Login or Register  to view this content.
    In the Task Sheet (Sheet2) code module:
    Please Login or Register  to view this content.
    If this does not solve your problem, please upload a sample file that does not work properly.

    Lewis
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    Wow this is perfect!! Thank you once again!!

  21. #21
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

    Re: Start / Pause timer Button

    Hi I have a different question but now once is replying, can you help me with that?

  22. #22
    Registered User
    Join Date
    03-07-2017
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    182

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. running timer in excel with start, pause and end button
    By melody10 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-23-2021, 04:36 AM
  2. Create running stopwatch/timer with 1 button (start/stop). No reset button.
    By leeroy2612 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-26-2021, 12:59 AM
  3. Start and Stop Timer with button
    By markusvirus in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-14-2017, 06:01 PM
  4. Start/Stop button help Timer auto update
    By Tortus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2014, 11:16 AM
  5. Countdown Timer in Excel with a "pause" and "start" button
    By bbhagwat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2013, 05:49 AM
  6. Replies: 0
    Last Post: 06-24-2013, 04:24 PM
  7. Countdown Timer Pause and Resume Button
    By table83 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-07-2010, 08:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1