userforms showing and hiding

L

Laurin

I have two userforms in my program. I set it up so that clicking on
command button on userform1 hides userform1 and shows userform2.
Userform2 is set up in the same way such that clicking on
commandbutton will hide userform2 and show userform1.

the problem is that the userforms are not the same size. Userform2 i
wide and short while userform1 is tall and skinny. And when I hide
userform and show the other userform (via the command buttons) you ca
still see the hidden userform behind the userform being shown. I
other words the userforms are not really being hidden. I've se
application.screenupdating to true thinking that might be the proble
but it isn't.

Here is the code in userform1:


Code
-------------------
Private Sub CommandButton2_Click()
UserForm1.Hide
UserForm2.Show
End Su
-------------------

And the code in userform2:


Code
 
G

Guest

It worked ok for me, but I don't have any other controls or code to consider.
Are you updating a control on one of the forms or doing something that may
be keeping the form active? Try putting "DoEvents" in the button click
events.

Private Sub CommandButton2_Click()
UserForm1.Hide
UserForm2.Show
DoEvents
End Sub
 
E

Excelibur

Laurin said:
Here is the code in userform1: Code
I don't see what you could be doing wrong... I tried with the exac
same code, and it works. Afterwards, I tried this:
Here is the code in userform1:

Code
-------------------
Private Sub CommandButton2_Click()
Unload UserForm1 ''changed this line
UserForm2.Show
End Su
-------------------

And the code in userform2:

Code
-------------------
Private Sub CommandButton2_Click()
UserForm2.Hide
UserForm1.Show
End Su
-------------------

which also worked.
Maybe it's because you set the screenupdating to True at the wron
moment? Test it by commenting out the lines that say 'Screenupdating
False'.


Edit: ok, seems it's already solved..
 
T

Tom Ogilvy

Private Sub CommandButton2_Click()
UserForm1.Hide
UserForm2.Show
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End Sub

Private Sub CommandButton2_Click()
UserForm2.Hide
UserForm1.Show
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top