Link to home
Start Free TrialLog in
Avatar of gwosgood
gwosgoodFlag for United States of America

asked on

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
Avatar of gwosgood
gwosgood
Flag of United States of America image

ASKER

note:    form.refresh does not work
ASKER CERTIFIED SOLUTION
Avatar of fulscher
fulscher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
fulscher,

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.

e.g.

Sub Command1_Click()

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

    Do While ( ... )
        'Process Records
        DoEvents
    Loop

    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!