PDA

View Full Version : How to use DoEvents in VBA



Timbo
01-03-2007, 08:43 AM
Hi,

I am running some code which takes sometime to complete, and I wish to display a message to the user in the form of a changing caption in a label on a userform. I only have one form open, but using DoEvents in the way I have used it, does not cause the caption to change. Basically, a series of proceedures run, and at the end of each one, I have used DoEvents to update the caption. Where have I gone wrong? Here is an example of the code:-

myform = DoEvents

If myform = 1 Then
Application.ScreenUpdating = True
With frmSelectFile
.lblprocessActual.ForeColor = vbBlack
.lblprocessActual.Caption = "Done"
.lblProcessFiled.ForeColor = vbRed
.lblProcessFiled.Caption = ">> Processing FILED data..."
End With
Application.ScreenUpdating = False
End If

many thanks if you can help

Tim
:banghead:

JonPeltier
01-03-2007, 10:06 AM
You just use DoEvents as a standalone command. I don't think it's what you want. Try .Repainting the form after updating it. Screen updating wouldn't affect the form either, it is concerned with updating the appearance of the workbooks and sheets in Excel.

With frmSelectFile
.lblprocessActual.ForeColor = vbBlack
.lblprocessActual.Caption = "Done"
.lblProcessFiled.ForeColor = vbRed
.lblProcessFiled.Caption = ">> Processing FILED data..."
.Repaint
End With

Timbo
01-04-2007, 03:03 AM
Many thanks Jon. The solution worked fine :thumb