Would like to update "text1.text = Time" (in its own sub) without having to call on its sub

Posted on 2006-05-11
Last Modified: 2010-05-01
I have a "Sub NewTime" dedicated JUST to update the time every 30 seconds or so. I call on it from other subs. the problem is sometimes other subs get wrapped up in their loops and 'NewTime' doesn't get called on until minutes later. Is there a way that I could have 'NewTime' run independently of the other subs, updating itself without needing to be called by other subs?
Question by:JohnDoeSr
    LVL 19

    Expert Comment

    Why not call NewTime from a timer every 30 seconds?

    LVL 12

    Assisted Solution

    I agree with Shauli and to clarify what he is actually referring to that you have to place a Timer control on your form and in the Timer() event
    you code it as follows:

    1. Set the "Interval" property of the Timer control to 1000 (which means that the timer fires every 1 second)
    2. Code your timer as follows:

    Private Sub Timer1()

      Static iSecond As Integer

      If iSecond >= 30 Then      
         Text1.Text = Time          'Update the time text box
         iSecond = 0                    'Reset counter to start again from 1
         iSecond = iSecond + 1    'Increment the seconds counter
      End If

    End Sub
    LVL 19

    Accepted Solution

    jkaios , why not set the interval to 30,000 and then do:

    Private Sub Timer1()
    Timer1.Enabled = False
    Call NewTime
    Timer1.Enabled = True
    End Sub

    LVL 12

    Expert Comment

    That's a good one Shauli, again I agree with you 100%... all credits should be on you

    LVL 18

    Expert Comment

    You could add DoEvents commands into the loops that are getting tied up.
    This would allow the Timer event to be triggered and run during the looping.

    Author Comment

    Worked great! I upped thepoints and am splitting them between jkaios for explaining things to me in laymans terms and Shauli for coming up with the idea.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    VBA Modification 5 35
    Use closed file on desktop in vba 6 49
    Microsoft Access combo box help 2 16
    Copy a row 12 31
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now