• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

What can I do to make my window refresh reliably

I am using the following code to indicate when my MS Access program is running a routine. It is meant to say "Reading..." while it waits for the function to run then "***" while it waits for the next timer loop. The labeling works sometimes and not others. How do I get it to work reliably?

    Me.TimerInterval = 0 'turn timer off while code runs
    Me.lblRunning.Caption = "Reading emails..."  'Change message on form
    Me.Form.Repaint      'repaint form so new message appears
    ReceiveMail    'run my function that reads emails
    Me.TimerInterval = 30000
    Me.lblRunning.Caption = "***"    'change caption on form
    Me.Form.Repaint      'repaint form so new message appears
0
Rob4077
Asked:
Rob4077
  • 5
  • 5
1 Solution
 
IrogSintaCommented:
See if this helps:
    Me.TimerInterval = 0 'turn timer off while code runs
    Me.lblRunning.Caption = "Reading emails..."  'Change message on form
    Me.Form.Repaint      'repaint form so new message appears
    Me.Painting = False
    ReceiveMail    'run my function that reads emails
    Me.TimerInterval = 30000
    Me.Painting = True
    Me.lblRunning.Caption = "***"    'change caption on form
    Me.Form.Repaint      'repaint form so new message appears
0
 
Rob4077Author Commented:
Seems to work - any reason?
0
 
Rob4077Author Commented:
No, spoke too soon, still only works sometimes
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
IrogSintaCommented:
Okay, how about:
    Me.TimerInterval = 0 'turn timer off while code runs
    Me.lblRunning.Caption = "Reading emails..."  'Change message on form
    Me.Form.Repaint      'repaint form so new message appears
    DoCmd.Echo False
    ReceiveMail    'run my function that reads emails
    Me.TimerInterval = 30000
    DoCmd.Echo True
    Me.lblRunning.Caption = "***"    'change caption on form
    Me.Form.Repaint      'repaint form so new message appears

And if that doesn't work, is there a loop in your ReceiveMail function where you could insert DoEvents?
0
 
Rob4077Author Commented:
I gave your code a quick run but it didn't work, however I have also since introduced a requery of a text box on the form that contains Now() and it too is disappearing.

I am getting tired and frustrated with this tonight (it's getting late over here and I have had a long day) so I will pack up for now.

Just to answer the question, I don't have any DoEvents anywhere in my code.

I will play around with resequencing but I was wondering if you could tell me what might cause this kind of behaviour. I thought Me.Form.Repaint would do just that but it doesn't seem to. What does me.painting = True/False do?
0
 
IrogSintaCommented:
Me.Repaint is suppose to work but I've seen times when other processes interfere with it.  Painting and Echo turn on or off screen repaint while you have some process running.  Painting is limited to the current form whereas Echo applies to all.  If you could add a DoEvents inside the loop that checks your emails, this may take care of your problem.
0
 
IrogSintaCommented:
If you cannot add the DoEvents in your ReceiveMail function, you could try adding a short loop prior to calling this function.  Something like this:
Me.Repaint
For i = 1 to 1000: DoEvents: Next
ReceiveMail
0
 
Rob4077Author Commented:
This seems to be a case of trial and error. I have two fields on the form, one is the label that tells the user that it's reading mail and the other is the current time, to show when the timer last ran. I just can't seem to get both refreshing, only one or the other will refresh and even then not reliably. I've tried all the suggested options including the 1000 DoEvents loop but none of them seem to work. The DoEvents loop actually makes it worse - neither field refreshes
0
 
IrogSintaCommented:
Just as a test, try increasing the value of the DoEvents loop to 10,000 instead of a 1000.  Then try 20,000 if you still don't get consistent results.
0
 
Rob4077Author Commented:
Hi IrogSinta,
I tried putting DoEvents and repaints in different places (trial and error) and found a combination that's reasonably reliable so I will leave it at that. If it doesn't display the labels 100% accurately I can live with it. Thanks for your suggestions that ultimately led me to a solution I can live with.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now