Userform show / hide

TheWennerWoman

Board Regular
Joined
Aug 1, 2019
Messages
151
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a userform, call it UserForm1. It contains five buttons. If the user clicks button1 I have some simple code that does
VBA Code:
Private Sub CommandButton1_Click()
UserForm2.Show
End Sub

UserForm2 appears with whatever data I have populated it with. That userform has a QUIT button which has some code that does
VBA Code:
Private Sub CommandButton1_Click()
Unload Me
End Sub

UserForm1 is then visible again.

I've had a couple of instances (sporadic) where UserForm1 has remained visible on top of UserForm2. Clicking on UserForm2 makes UserForm1 disappear. I don't know if Excel is just having a moment but this file is aimed at very non-techy people and two forms visible is going to confuse them.

Is there a way of forcing UserForm1 to disappear and then reappear once UserForm2 is closed so that I can be sure only one form is visible at any one time?

This is in a corporate environment so calls to the API aren't an option.

Thanks for reading!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,266
You could try this in UF1's code that calls UF2.
VBA Code:
Private Sub CommandButton1_Click()
    Me.Hide
    UserForm2.Show
    Me.Show
End Sub
 

Forum statistics

Threads
1,175,752
Messages
5,899,276
Members
434,759
Latest member
carcharoth

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
Top