+ Reply to Thread
Results 1 to 7 of 7

Form not hiding

  1. #1
    Registered User
    Join Date
    07-23-2004
    MS-Off Ver
    2007
    Posts
    94

    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

  2. #2
    Dave Peterson
    Guest

    Re: Form not hiding

    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

  3. #3
    Registered User
    Join Date
    07-23-2004
    MS-Off Ver
    2007
    Posts
    94
    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?

  4. #4
    Dave Peterson
    Guest

    Re: Form not hiding

    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

  5. #5
    Registered User
    Join Date
    07-23-2004
    MS-Off Ver
    2007
    Posts
    94
    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.

  6. #6
    Dave Peterson
    Guest

    Re: Form not hiding

    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

  7. #7
    Registered User
    Join Date
    07-23-2004
    MS-Off Ver
    2007
    Posts
    94
    It works for me now too (as-is). I didnt think to enable screenupdating.

    Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1