Results 1 to 7 of 7
  1. #1
    roberto21 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    17

    On timer event strange effects

    Trying to learn access, I played with a simple access app. An initial form is displayed, and the user can select an operation to be performed.
    Let's say I want info on a customer. Another form is opened, the user enters the name, the related info are displayed, and when the user is done, he can press enter (and the form is redisplayed empty, ready for next name) or he can opt for exiting pressing the button EXIT (and the initial form is redisplayed). This works fine.




    I tried to add a simple clock on the initial form. So, following suggestions found online, I defined a label called Clock, set the form timer to 1000, and added the code for the timer event


    Code:
    Private sub form_timer()
    	me.Clock.caption = time
    end sub
    Now, when I open the initial form, the clock is displayed and updated every second, as it should. Fine? No. What happens is the following. The user opens the info form, enters a name and the related info are displayed. Now he presses enter, and the form is NOT cleared; if he presses EXIT, the initial form is NOT displayed (blank screen)


    It is clear that the timer event code is causing this (removing it brings things to normal again), but why? Is there something else that must be taken care of?


    Thank you for your patience... with a rookie.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,942
    I have never played around with the Form Timer, but I suspect it is too busy updating that control every second?
    To see if that is the case, change to every minute.

    If that fixes it, lower the interval until it breaks again.
    I have a clock on the taskbar, so never saw the need for a time on a form. Day countdown yes though.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Try Repaint method on the cleared form.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    roberto21 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    17
    Thanks a lot.
    I don't know what repaint does, but I have the sequence

    Docmd.close
    DoCmd.OpenForm ("FrmCustomer")

    that should close and reopen the form. Is this equivalent or not?

  5. #5
    roberto21 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    17
    Thank you a lot. I can't believe this: setting the timer to 60000 (1 minute) works, anything less doesn't. I was convinced that 1 second is an eternity for a computer, let alone one minute... and the program is doing nothing...
    Of course I don't need a clock either, I was just fooling around, but this seems really strange.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,978
    I have used code exactly as shown for many years to update time on a form every second.
    However, that can use up as lot of resources

    Remember Access is single thread - only one action can occur at a time
    The timer code works perfectly providing no other code is currently running and which takes priority

    Say for example you have code to run a procedure which takes 10 seconds to complete

    The timer updates the clock before the procedure starts then the procedure runs preventing the clock updating.
    Ten seconds later, the procedure is completed and the clock updates again jumping over the 'missed 10 seconds'

    You may be better off just updating every minute. Your users won't notice if the update is a few seconds late occasionally
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    roberto21 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    17
    Thanks again for your attention. I was a little pessimistic yesterday, it seems that the critical value is between 5 and 10 seconds (with 5 it doesn't work, with 10 it seems to work). In any event, I still am wondering why this happens. Granted the fact that access is single threaded etc, but why the code to close and reopen the form is not executed at all? Following your explanation, the timer should stop a few second, and then, when the form is redisplayed (empty, hopefully), "jump" over the missing seconds (note that in this form the clock is NOT displayed). And what happens to the code for redisplaying the initial form? The initial form is not redisplayed at all!Probably I am missing something basic here, but thank you anyhow for the explanations.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. On Timer event issue
    By jrock1203 in forum Forms
    Replies: 1
    Last Post: 05-01-2018, 09:42 AM
  2. Access as event timer?
    By Jennifer Murphy in forum Access
    Replies: 1
    Last Post: 01-31-2014, 08:30 PM
  3. Timed Reminder Box; Event Timer?
    By WEJ in forum Access
    Replies: 6
    Last Post: 05-26-2013, 03:12 PM
  4. Timer Event Code Stops After First Run
    By burrina in forum Forms
    Replies: 3
    Last Post: 02-19-2013, 09:46 AM
  5. Timer Event - Why does this happen
    By Rhino373 in forum Programming
    Replies: 2
    Last Post: 05-26-2011, 07:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums