ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Form not hiding (https://www.excelbanter.com/excel-discussion-misc-queries/40829-form-not-hiding.html)

LB79

Form not hiding
 

Hello - Hope someone can help - this is driving me mad.
Ive looked at the other threads relating to this but the advice hasnt
seemed to work for me.
I have a userform that has a button. When the button is pushed the
first userform should close and and a second should open. This works
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

Thanks


--
LB79
------------------------------------------------------------------------
LB79's Profile: http://www.excelforum.com/member.php...o&userid=12156
View this thread: http://www.excelforum.com/showthread...hreadid=396483


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).


LB79 wrote:

Hello - Hope someone can help - this is driving me mad.
Ive looked at the other threads relating to this but the advice hasnt
seemed to work for me.
I have a userform that has a button. When the button is pushed the
first userform should close and and a second should open. This works
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

Thanks

--
LB79
------------------------------------------------------------------------
LB79's Profile: http://www.excelforum.com/member.php...o&userid=12156
View this thread: http://www.excelforum.com/showthread...hreadid=396483


--

Dave Peterson

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?


--
LB79
------------------------------------------------------------------------
LB79's Profile: http://www.excelforum.com/member.php...o&userid=12156
View this thread: http://www.excelforum.com/showthread...hreadid=396483


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?)

LB79 wrote:

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?

--
LB79
------------------------------------------------------------------------
LB79's Profile: http://www.excelforum.com/member.php...o&userid=12156
View this thread: http://www.excelforum.com/showthread...hreadid=396483


--

Dave Peterson

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.


--
LB79
------------------------------------------------------------------------
LB79's Profile: http://www.excelforum.com/member.php...o&userid=12156
View this thread: http://www.excelforum.com/showthread...hreadid=396483


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


LB79 wrote:

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.

--
LB79
------------------------------------------------------------------------
LB79's Profile: http://www.excelforum.com/member.php...o&userid=12156
View this thread: http://www.excelforum.com/showthread...hreadid=396483


--

Dave Peterson

LB79


It works for me now too (as-is). I didnt think to enable
screenupdating.

Thank you


--
LB79
------------------------------------------------------------------------
LB79's Profile: http://www.excelforum.com/member.php...o&userid=12156
View this thread: http://www.excelforum.com/showthread...hreadid=396483



All times are GMT +1. The time now is 08:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com