Consulting

Results 1 to 14 of 14

Thread: Close a UserForm and open another

  1. #1
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location

    Close a UserForm and open another

    In my Vba code (Excel 2007) I have a UserForm , with a CommandButton on it i close this UserForm and open another UserForm.
    On Win 7 the first UserForm as aspected, disapper; On WInXP remain on screen.
    Any ideas why?
    Sub CommandButton4_Click()
    Unload UserFormRapportino
    FormRipetiGiorno.Show
    End Sub
    Thanks in advance for help
    Last edited by Aussiebear; 04-13-2023 at 01:04 PM. Reason: Adjusted the code tags

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Perhaps
    Sub CommandButton4_Click()
        UserFormRapportino.Hide 
        Unload UserFormRapportino 
        FormRipetiGiorno.Show 
    End Sub
    I've heard that there is a quirk about Unloading, the operation doesn't completely take place until EndSub is reached. Hide, on the other hand, works immediatly.
    Last edited by Aussiebear; 04-13-2023 at 01:05 PM. Reason: Adjusted the code tags

  3. #3
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location
    Quote Originally Posted by mikerickson
    Perhaps
    Sub CommandButton4_Click()
    UserFormRapportino.Hide 
    Unload UserFormRapportino 
    FormRipetiGiorno.Show 
    End Sub
    I've heard that there is a quirk about Unloading, the operation doesn't completely take place until EndSub is reached. Hide, on the other hand, works immediatly.
    Hi Mike, before posting i try also the Hide instruction as you suggest, but it not work. The first UserForm remain visible (in WinXP, se same code in Win 7 work)??
    Last edited by Aussiebear; 04-13-2023 at 01:05 PM. Reason: Adjusted the code tags

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    This works for me on 2010 and xp.
    Private Sub CommandButton1_Click()
      Unload Me
      UserForm2.Show
    End Sub
    Last edited by Aussiebear; 04-13-2023 at 01:06 PM. Reason: Adjusted the code tags

  5. #5
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location
    Quote Originally Posted by Kenneth Hobs
    This works for me on 2010 and xp.
    Private Sub CommandButton1_Click()
    Unload Me
    UserForm2.Show
    End Sub
    Thanks for reply Kenneth, i try your suggestion but not work in 2007 + Xp.

    I am out of ideas...
    Last edited by Aussiebear; 04-13-2023 at 01:07 PM. Reason: Adjusted the code tags

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Must be something wacky with 2007. Try posting a simple example file so that those with 2007 can test. You may have something else going on.

  7. #7
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location
    Quote Originally Posted by Kenneth Hobs
    Must be something wacky with 2007. Try posting a simple example file so that those with 2007 can test. You may have something else going on.
    Ok Kennet, here is an example file, click the "Inserisci Giorno" button, and in form click the red button and see....

    Thanks again
    Attached Files Attached Files

  8. #8
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    Hi Raman,

    Perhaps some slight bug in your code might be causing Application.ScreenUpdating to not be set back to true at the time you are hiding the form. - I've seen that functionality vary on different pc's.

  9. #9
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location
    Quote Originally Posted by frank_m
    Hi Raman,

    Perhaps some slight bug in your code might be causing Application.ScreenUpdating to not be set back to true at the time you are hiding the form. - I've seen that functionality vary on different pc's.
    Thanks for reply, Frank but i i try to disable ScreenUpdating=False, but not work.

    Maybe my OS need a reinstall....

    Thanks again

  10. #10
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    Quote Originally Posted by Rayman
    Thanks for reply, Frank but i i try to disable ScreenUpdating=False, but not work.

    Maybe my OS need a reinstall....
    Hi again Rayman,

    Didn't you say that you had the same issue with more than one pc? If so, that is strong evidence that reinstalling will not help.
    * I would try creating a new workbook that has only the two user forms and the code that loads and unloads them. If that gets rid of the issue then try adding chunks of your code back in until you can determine which part of the code is interfering.

    Then post a new sample workbook here.

  11. #11
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location
    Quote Originally Posted by frank_m
    Hi again Rayman,

    Didn't you say that you had the same issue with more than one pc? If so, that is strong evidence that reinstalling will not help.
    * I would try creating a new workbook that has only the two user forms and the code that loads and unloads them. If that gets rid of the issue then try adding chunks of your code back in until you can determine which part of the code is interfering.

    Then post a new sample workbook here.
    That makes sense Frank, ill try and let you know...

    Thanks
    Last edited by Aussiebear; 04-13-2023 at 01:07 PM. Reason: Adjusted the code tags

  12. #12
    VBAX Regular
    Joined
    Mar 2011
    Posts
    92
    Location
    Quote Originally Posted by frank_m
    Hi again Rayman,

    Didn't you say that you had the same issue with more than one pc? If so, that is strong evidence that reinstalling will not help.
    * I would try creating a new workbook that has only the two user forms and the code that loads and unloads them. If that gets rid of the issue then try adding chunks of your code back in until you can determine which part of the code is interfering.

    Then post a new sample workbook here.
    Hi Frank ,
    thanks to your suggestion i have found the problem: the initialization code of the second UserForm have in it "ScreenUpdating= False" not reset to "True" at end of initializan.
    Strange is that the same code in other Pc with Win7 works fine with this error..
    Thanks again

  13. #13
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    Quote Originally Posted by frank_m
    Hi Raman,

    Perhaps some slight bug in your code might be causing Application.ScreenUpdating to not be set back to true at the time you are hiding the form. - I've seen that functionality vary on different pc's.
    Hi Rayman,

    I know it's weird, but I've several times had that same thing happen where some pc's, or different operating systems behave differently with screen updating.. (in other words some update the screen for certain objects even though updating is set to false, and some do not.)

    Glad to hear that you got it going.

    Frank

  14. #14
    VBAX Newbie
    Joined
    Oct 2018
    Posts
    3
    Location
    Quote Originally Posted by Kenneth Hobs View Post
    This works for me on 2010 and xp.
    Private Sub CommandButton1_Click()
      Unload Me
      UserForm2.Show
    End Sub


    This was very useful, thanks for sharing you experience
    Last edited by Aussiebear; 04-13-2023 at 01:09 PM. Reason: Adjusted the code tags

Posting Permissions

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