• Form On Time Event acting strange (A2K SR1)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Form On Time Event acting strange (A2K SR1)

    Author
    Topic
    #382475

    I am using a Forms onTimer event to launch some actions. The Timer Interval is set to 1000. The On timer event increments a counter that starts from zero and increases by 1 each time the timer fires. The timer is re-set to zero by a MouseMove or KeyDown event. Here are the problems I have encountered. The timer is set as a public variable.

    1. Upon monitoring the counter, the counter increments by 1, 2, or sometime 3 each time it fires.
    2. The MouseMove event only resets the timer to zero on the first movement and then does not do it again.
    3. The KeyDown event never resets the time.

    Any insights as to why this is happening?? dizzy

    Viewing 0 reply threads
    Author
    Replies
    • #648624

      Gary,

      I had this great reply already for you, then I went back to reverify my tests and I duplicated exactly what you said.

      That being said, here is what I can figure

      1) The way i was monitoring the counter was to change the caption of the form and occasionally it would jump 2 or 3. For me, I think it is because of the screen refreshing too slowly, so it would only refresh every other time the counter changed. So I suspect you are running into a similar challenge.

      2) Is your MouseMove Event the form’s mousemove event? You may need to add your code to all the controls on the form, including the details section. Once I added the Details MouseMove event to reset the counter, as long as the mouse pointer was over the form, even not moving, the event would fire. To get around this, I would suggest static variables in the Detail MouseMove event to track the last position of the mouse pointer and only if they are different reset the counter.

      3) Does the Form KeyDown event even fire? If not, I would suspect that you don’t have the Form’s Key Preview property set to yes.

      All this make sense?

      • #648650

        Bryan,

        Thanks for the reply.

        Items 1 and 3 make sense.

        Item 2 sounds like too much work except for perhaps the detail section, which I will have to try. I used a text box to display the current counter on the form while it was active. I have used this method for reviewing loops before and have never had a problem. Perhaps the refresh is causing a problem, I just don’t know.

        Thanks for the suggestions.

        • #648671

          How are you determining that it is incrementing it wrong? Are you stepping through the code, or simply watching a counter? Timer events WILL back up. Which means that if a piece of code takes 3 or 4 cycles of a timer to complete, the timer event will fire 3 or 4 times right in a row. A good example of this is setting the timer interval to 1000, and just having it set a label’s caption to Now(). That makes a simple clock. However, if you watch that clock as you use other objects in your database, you’ll notice that it is going to skip a bit here and there. Setting the timer event to 100 fixes most situations except for long code runs…. (You need a doevents for that, but you must be careful that other events don’t fire that will ‘hurt’ the function with DoEvents in it.)

          Drew

          • #648687

            Drew,

            I took the lazy way out and did not step through the code. Setting the timer to 100 seems to have fixed the issue at hand.

            Thanks

    Viewing 0 reply threads
    Reply To: Form On Time Event acting strange (A2K SR1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: