Back to back userform displays... 2nd userform shows up blank

jbrown2424

New Member
Joined
Mar 10, 2022
Messages
8
Office Version
  1. 365
NEW TO VBA and the forum so thanks in advance...
I have a command button that takes a few minutes to process and while this code runs I would like to have a userform "PleaseWaitTrain" display (with a did you know fact on it) for 10 seconds then disappear and a 2nd userform "PleaseWaitTw" display for 10 seconds.

These 2 userforms both work perfectly when I call them individually, but when I call them from the same Sub the 1st userform operates as desired and then then 2nd displays a blank userform for 10 seconds.

Below is my code...

Public Sub PleaseWaitTrain_userform_initialize()
PleaseWaitTrain.Show vbModeless
Application.WAIT Now + TimeValue("0:00:10")
Unload PleaseWaitTrain
End Sub

Public Sub PleaseWaitTw_userform_initialize()
PleaseWaitTw.Show vbModeless
Application.WAIT Now + TimeValue("0:00:10")
Unload PleaseWaitTw
End Sub

Public Sub call_macro()
Call PleaseWaitTrain_userform_initialize
Call PleaseWaitTw_userform_initialize
End Sub

Any help would be greatly appreciated.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Such things can be a bit wonky in Office apps because control can return back to code and/or other processes before the object (e.g. form) has a chance to finish rendering. All I can suggest is try DoEvents after the line to .Show the form, or after the .Wait line, or both.
 
Upvote 0
I recommend not using Application.Wait as it locks the user interface.
I would use a loop alternative as follows :

VBA Code:
Public Sub PleaseWaitTrain_userform_initialize()
    PleaseWaitTrain.Show vbModeless
    Delay 10
    Unload PleaseWaitTrain
End Sub

Public Sub PleaseWaitTw_userform_initialize()
    PleaseWaitTw.Show vbModeless
    Delay 10
    Unload PleaseWaitTw
End Sub

Public Sub call_macro()
    Call PleaseWaitTrain_userform_initialize
    Call PleaseWaitTw_userform_initialize
End Sub

Public Sub Delay(ByVal HowLong As Single)
    Dim t As Single
    t = Timer
    Do: DoEvents
    Loop Until Timer - t >= HowLong Or UserForms.Count = 0
End Sub
 
Upvote 0
Solution
Such things can be a bit wonky in Office apps because control can return back to code and/or other processes before the object (e.g. form) has a chance to finish rendering. All I can suggest is try DoEvents after the line to .Show the form, or after the .Wait line, or both.
Simple fix and works perfect now. Thank you!
 
Upvote 0
I recommend not using Application.Wait as it locks the user interface.
I would use a loop alternative as follows :

VBA Code:
Public Sub PleaseWaitTrain_userform_initialize()
    PleaseWaitTrain.Show vbModeless
    Delay 10
    Unload PleaseWaitTrain
End Sub

Public Sub PleaseWaitTw_userform_initialize()
    PleaseWaitTw.Show vbModeless
    Delay 10
    Unload PleaseWaitTw
End Sub

Public Sub call_macro()
    Call PleaseWaitTrain_userform_initialize
    Call PleaseWaitTw_userform_initialize
End Sub

Public Sub Delay(ByVal HowLong As Single)
    Dim t As Single
    t = Timer
    Do: DoEvents
    Loop Until Timer - t >= HowLong Or UserForms.Count = 0
End Sub
Works like a charm...Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top