Change Userform Label caption when a loop is running in background

I

itsyash

Hi,

I have a VBA userform. On Button_Click event I have given a task for
the macro the open some files, process and close them. While this is
happening I want the user to see the progress. So i have a label on the
userform which says 'No of files processed'. While I am in the loop,
just before moving to the next file, I use

'frmMain.lblProcessedFiles.Caption = FilesProcessed'

At this time, the value does not show on the label because the loop is
running on the file in the background. Technically the caption of the
label changes but it does not show until the loop ends completely.

I tried using 'frmMain.hide' and 'frmMain.show'. This updated the value
of the label but I think because it goes to form_load event it stops
the loop in the background.

I dont want to put the rest of the code form_load event as this is not
correct.

Please help me.

Thanks,
Yash
 
A

Andy Pope

Hi,

Add a Doevents after you change the caption.

'-----
frmMain.lblProcessedFiles.Caption = FilesProcessed
DoEvents
'-----


Cheers
Andy
 

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

Top