Form not hiding

L

LB79

Hello - Hope someone can help - this is driving me mad.
Ive looked at the other threads relating to this but the advice hasn
seemed to work for me.
I have a userform that has a button. When the button is pushed th
first userform should close and and a second should open. This work
except the first userform stays visible in the background.
Ive tried using DoEvents and unloading but this hasnt worked for me.
Ive tried the following codes:

Sub B()
form2.Show
form1.Hide
DoEvents
End Sub

Sub A()
form1.Hide
form2.Show
DoEvents
End Sub

Thank
 
D

Dave Peterson

Shouldn't B be:

Sub B()
form1.Hide
form2.Show
DoEvents
End Sub

Try changing the doEvents to:
msgbox "hi"

And you'll see when it gets executed (in the original sub).
 
L

LB79

Thanks for that.
I changed the DoEvents to MSGBOX "hi" and it didnt pop up until i
closed the second form, which indicates that DoEvents is being
ignored?
How can i force DoEvents to work where i want it to?
 
D

Dave Peterson

I don't think it's being ignored. I think your code is waiting for the other
userform to finish what it has to do.

So you'll either have to rearrange the order of what you do (my first
suggestion) or if you're running xl2k+, you can load the second form like:

Sub B()
form2.Show false
form1.Hide
DoEvents
End Sub

The false means that you're loading the form is modeless. The user can click on
cells and continue to work. (It may not be what you want to allow.)

(why not just change the order of the .hide and .show?)
 
L

LB79

Im still not getting this. My code is:

Private Sub CommandButton1_Click()
Menu1.Hide
Menu2.Show
DoEvents
End Sub

but the Menu1 is still showing in the background. Ive tried adding in
more then 1 DoEvents too but i cant seem to get it.
 
D

Dave Peterson

Your code worked fine for me (as-is).

Did you try the doEvents this way?
Option Explicit
Private Sub CommandButton1_Click()
menu1.Hide
DoEvents
menu2.Show
DoEvents
End Sub

Is this all your code (or just a snippet)?

If you have "application.screenupdating = false", then turn it back on after you
hide the form:

Option Explicit
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
'more code here
menu1.Hide
Application.ScreenUpdating = True
'application.screenupdating = false 'if you want
menu2.Show
DoEvents
End Sub
 
Top