Any suggestions on how to avoid the long delay in rendering this form?
I have a userform with a label that says ‘Please wait, downloading’ and no other controls. When the user requests a data download (an async API request) I turn off keyboard entry, and show the ‘please wait’ form. The callback that processes the data re-enables keyboard entry and hides the form. Works like a charm.
Except that it initially pops up as a blank, white rectangle, and then takes several seconds (as many as 5) to paint. My other userforms (modal, for data entry) are painted instantly I’ve never even noticed that they start out white.
Here’s how I show the form before making the async data request:
' Deactivate the keyboard.
Application.OnKey "^d", "KeyboardOn"
Application.DataEntryMode = True
' Display the splash form non-modally.
ssiWaitDialog.TaskDone = False
ssiWaitDialog.Show False
Here’s how it’s removed in the callback:
' Close the splash form.
ssiWaitDialog.TaskDone = True
ssiWaitDialog.Hide
' Re-activate the keyboard.
Application.DataEntryMode = False
Here’s the form code:
' Set true when the long task is done.
Public TaskDone As Boolean
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Cancel = Not TaskDone
End Sub
The problem form’s property values only differs significantly from my other forms modal=false, and I’ve set the cursor to an hourglass. Less significant differences are hight / width and the label font size.
Adding ‘DoEvents’ after the show method call fixed the problem. Here’s how the show form code reads now: