Status meter not moving until sub ends

M

microfich

Hi,

I've installed (via VBA) a status meter. The meter appears at the beginning
of the execution but does not increment until either I break the code or the
end of execution. Using Access 2003.

Code sample:


SysCmd acSysCmdInitMeter, "Processing", 5000
lngCount = 0

Do While tblname.EOF=False

....process stuff...

lngCount = lngCount + 1
SysCmd acSysCmdUpdateMeter, lngCount
tblname.MoveNext
Loop

SysCmd acSysCmdRemoveMeter

Any ideas? Thanks!
 
K

Klatuu

I am not positive this will do it, but I think it might

Add a repaint after this line:

SysCmd acSysCmdUpdateMeter, lngCount

'New Line
Me.Repaint
 
M

microfich

Nice try, but still no luck...

Klatuu said:
I am not positive this will do it, but I think it might

Add a repaint after this line:

SysCmd acSysCmdUpdateMeter, lngCount

'New Line
Me.Repaint
 
E

Eric Gerds

I Hope this helps
I put the following lines in a form instead of a module
I also specified the event on timer and gave Timer Interval 1000

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)
SysCmd acSysCmdInitMeter, "Processing", 5000
Dim lngCount As Long, i As Long, x As Long
lngCount = 0
For i = 1 To 5000
For x = 1 To 999999: Next ' something to keep the processor busy
lngCount = lngCount + 1
SysCmd acSysCmdUpdateMeter, lngCount
Next
SysCmd acSysCmdRemoveMeter
End Sub

Private Sub Form_Timer()
Me.Repaint
End Sub
 
T

Tony Toews [MVP]

microfich said:
I've installed (via VBA) a status meter. The meter appears at the beginning
of the execution but does not increment until either I break the code or the
end of execution. Using Access 2003.

I prefer using some rectangle controls on a form as they are much more
visible to the user. See the Progress Bars and Microsoft Access page
at http://www.granite.ab.ca/access/progressbar.htm for more info.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
M

microfich

Thanks, Tony. Used your technique and like the flexibility, however, at
times the meter does not move at all and other times it works fine. Just
launching via a command button. What I do notice happening is a new instance
of Access appears down below in my task bar when the meter does not move.
When no new instance appears, it runs fine. Is it possible something is not
getting set/reset properly for this to work consistently?
 
T

Tony Toews [MVP]

microfich said:
Thanks, Tony. Used your technique and like the flexibility, however, at
times the meter does not move at all and other times it works fine. Just
launching via a command button. What I do notice happening is a new instance
of Access appears down below in my task bar when the meter does not move.
When no new instance appears, it runs fine. Is it possible something is not
getting set/reset properly for this to work consistently?

I have no idea why you are seeing a second instance of Access. That
makes no sense at ll.

Now sometimes you have to throw in DoEvents or me.repaint to get the
meter to work but I think I have that in there. Also if some queries
only take a fraction of a second to execute and others ten seconds
that could be misleading. What you could do there is add another
control and put the count value in there. Then you might get a better
idea.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
M

Michel Walsh

Timer and Paint are low priority event and may not fire if higher priority
message are still in the queue of messages. In fact, the timer and paint
messages are executed only if they are no other messages in their windows
messages queue: if they are met and other messages exist, they are pushed
back in the queue. As example, even if you make a timer to occur each 100
milliseconds, but, for the same message queue, run a loop which will take 1
second to be executed, the timer will 'forget' to fire about 10 times ( a
new message won't be generated if an existing message of Paint or Timer is
already in the queue; for the paint, the message will be modified so that
the regions to repaint will be 'aggregated' ).

You may need to add a

DoEvents

after your code changed the meter value. The DoEvents basically gives the
chance to the message queue to be dispatched before the VBA-code thread of
execution resumes. That does not always work since the dispatching process
may have something else than the Painting message. Also, since EVERY
application with the same priority (or higher) can de-schedule the VBA-tread
of execution too, other messages can thus be placed in your application
messages-queue while that occur... which will cause your Paint/Timer to not
be dispatched.

So you can try two DoEvents, but it may just be so that the hierarchy of the
messages queues are not favorable to your cause...



Vanderghast, Access MVP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top