PDA

View Full Version : [SOLVED:] Close a UserForm and open another



Rayman
06-08-2011, 06:43 AM
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

mikerickson
06-08-2011, 06:46 AM
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.

Rayman
06-08-2011, 06:57 AM
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)??

Kenneth Hobs
06-08-2011, 07:04 AM
This works for me on 2010 and xp.

Private Sub CommandButton1_Click()
Unload Me
UserForm2.Show
End Sub

Rayman
06-08-2011, 07:27 AM
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...

Kenneth Hobs
06-08-2011, 08:10 AM
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.

Rayman
06-08-2011, 09:01 AM
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

frank_m
06-08-2011, 11:17 AM
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.

Rayman
06-08-2011, 03:43 PM
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

frank_m
06-08-2011, 05:26 PM
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.

Rayman
06-09-2011, 03:34 AM
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

Rayman
06-09-2011, 04:55 AM
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

frank_m
06-09-2011, 05:03 AM
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. :beerchug:

Frank

controz
11-02-2018, 02:26 AM
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