views:

7

answers:

1

I have a simple VBA program to download attachments from a Mail Item; I'm launching a Macro (that is a 'sub' in a Module), which does a 'Form.Show' to launch a User Form. There is a button on the User Form to kick of the actual download - the download sub is located back in the Module code, not the form code.

Here's the code I'm using for the button:

Private Sub BTN_Download_Click()
    Me.MousePointer = fmMousePointerHourGlass
    Me.BTN_Download.Enabled = False
    Utils.DownloadAttachments
    Me.BTN_Download.Enabled = True
    Me.MousePointer = fmMousePointerDefault
End Sub

I'm trying to present a well-behaved UI to the user: temporarily disabling the button and showing an Hour Glass when the operation is in action, and then re-enabling the button and restoring the default Mouse Pointer when complete.

What actually happens is that the GUI becomes unresponsive, the button never appears to be disabled, and I don't see the hour glass pointer.

How can I achieve this ? (I have tried moving the GUI code back to the Module (MyForm.MousePointer=...) - this also doesn't work unfortunately. I have tried creating two additional Sub, 'Busy' and 'UnBusy', and calling this direcly from the Sub above - which works slightly better, but still there is a longish delay before the GUI looks 'Busy' to the user).

Is there a way of ensuring the GUI is updated first, and then defering the actual bulk of the work until this is complete ?

A: 

Found the answer: 'DoEvents' - in fact the article below is talking about how 'DoEvents' is the older way of yielding control back to the GUI for refresh purposes in older versions of VB - seems to work well with VBA as well.

http://msdn.microsoft.com/en-us/library/aa719109%28VS.71%29.aspx
monojohnny