VB form blank during heavy process

I have an application processessing upwards of 80000 records.
I have a progress bar to track progress of records
screen does not refresh with new progress information while in processing loop
i.e. no 10%, 15%, ...

any suggestions on how to get the progress bar (and rest of form) to display during this process time?

note question is urgent
gwosgoodIT MgrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gwosgoodIT MgrAuthor Commented:
note:    form.refresh does not work
Yes - add a DoEvents command in the most inner loop. DoEvents gives the OS the chance to process other events which have queued up - this includes repainting the UI.

You'll probably notice that DoEvents is quite expensive in terms of run-time of your program. Therefore, I'd suggest to do a DoEvents only every tenth (or so) time:

Dim DECnt as Long  'DoEvent counter
Const DETrigger = 10

if DECnt = 0 Then DoEvents
DECnt = DECnt + 1
If DECnt >= DETrigger Then DECnt = 0


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gwosgoodIT MgrAuthor Commented:

very well done
very simple and complete solution, much appreciated
Note that DoEvents will allow the user to interact with the form while your loop is running.  You should therefore take care when using DoEvents to prevent undesired events from triggering while your loop is running.  This may include disabling the command button which runs the loop.


Sub Command1_Click()

    Command1.enabled = false ' Disable to prevent reentrance
    bProcessing = True ' flag that the loop is running

    Do While ( ... )
        'Process Records

    bProcessing = false
    Command1.enabled = true ' Reenable after complete

End Sub

Also take care that you do not unexpectedly exit the program in the middle of the loop

Sub Form_QueryUnload(...)

    'Check the state of the processing...
    If bProcessing Then
         'The loop is running ...

If you do not want to use DoEvents, then you may try:

Progress1.Value = x
Progress1.Refresh 'Redraw the progressbar

Hope it helps!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.