Userform does not unload

Mel B.

New Member
Joined
Jan 21, 2005
Messages
6
I have a userform whereby users specify an input using button controls. When the user clicks OK, the form should unload and then a subroutine is executed that loads a second userform telling the user to "Please Wait" while it executes. The problem I'm having is that the first userform does not unload and stays in the background behind the second userform. Is there any special way to unload or suppress a userform? Here's my code:

UserForm1 code looks like (the variable Model is user input):

Public Sub OKButton_Click()
Dim Model As Integer
Model = 0
If Model1 Then Model = 1
If Model2 Then Model = 2
Unload UserForm1
SubMacro (Model)
End Sub

SubMacro code looks like:

Public SubMacro (Mode)
Application.ScreenUpdating = False
With PleaseWaitForm
.Show (Modeless)
.Repaint
End With

' there is other code here

End Sub

Any help would be greatly appreciated. Thanks!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Add the second line. form will unload

Public Sub OKButton_Click()

Unload Me
Dim Model As Integer

Mike
 
Upvote 0
Thanks for your reply Mike. I tried what you said to do and the form still does not unload.

Any other thoughts would be appreciated.

Thanks!
 
Upvote 0
Since you're showing in vbModeless modality, you're right, your dismissal needs to be driven by a form event. That said, putting either
Code:
unload me
or
Code:
me.hide
unload me
worked for me to dismiss the userform shown using vbModeless
 
Upvote 0
Thanks for your reply. I tried as you suggested but the userform still does not unload. By the way, I'm not loading the first form as modeless. Is there any other way to unload or suppress a userform?

Your help is greatly appreciated!
 
Upvote 0
If you are not showing the first form modelessly then your "OK Button" click event needs to say Me.Hide. Execution will then resume at the statement that follows the .Show that called the UF in the first place. After you read/process any needed values from the form, you should be able to use an Unload UserFormx in the procedure that .Showed the UF.

HTH
 
Upvote 0
I figured out my problem. I had ScreenUpdating set to False somewhere else which ultimately does not allow the form to unload until processing is completed.

Thanks for your help!
 
Upvote 0
Mel,

Thanks for posting back and letting us know. That's a good tidbit to know. I would not have suspected that.

Regards,
 
Upvote 0

Forum statistics

Threads
1,202,914
Messages
6,052,532
Members
444,590
Latest member
GCLee

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