....but i see your point..
when forms are MODAL the stack keeps growing.
--
keepITcool
|
www.XLsupport.com | keepITcool chello nl | amsterdam
keepITcool wrote :
ahh!...
are your forms Modeless or Modal?
if your forms showmodal properties are false
(and thus are shown modeless by default)
then my code should work..
if your forms are modal:
remove the terminate proc in userform2
change userform1 proc to
Private Sub CommandButton1_Click()
Me.Hide
UserForm2.Show
Me.Show
End Sub
--
keepITcool
www.XLsupport.com | keepITcool chello nl | amsterdam
Peter T wrote :
Hi KeepItCool - thanks for responding
I had tried similar to your suggestion before. It works for a 2 way
switch between forms 1 & 2, but then seizes on form 2 the second
time it is show'ed.
UF1 CB1 Me.Hide UF2 show 'OK
UF2 CB1 Me.Hide UF2 Term' UF1 show 'OK
UF1 CB1 Me.Hide UF2 show 'OK
now UF2 is displayed but no way to exit. No event is triggered with
CommandButton1_click and cannot close UF2 with the little "x",
need to reset the project!
Thoughts ?
Regards,
Peter T
"keepITcool" wrote in message
.com...
sub ShowForm1
userform1.show
end sub
Option Explicit
'code for userform1
Private Sub CommandButton1_Click()
Me.Hide
UserForm2.Show
End Sub
Private Sub UserForm_Activate()
MsgBox "UF1 show"
End Sub
Private Sub UserForm_Initialize()
MsgBox "UF1 load"
End Sub
Private Sub UserForm_Terminate()
msgbox "UF1 done"
End Sub
Option Explicit
'code for userform2
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Terminate()
UserForm1.Show
End Sub
--
keepITcool
www.XLsupport.com | keepITcool chello nl | amsterdam
Peter T wrote :
From code initiated in my main form1, I want to hide form1 and
show form2. When done with form2, then re-show form1.
No matter which way I try and do this, my code runs up in
multiple stacks which don't terminate until final exit. In the
example below, if I switch forms several tmes by pressing
CommandButtons 1 & 2 on main form1, only when I finally exit
are all the procedures completed.
This contrived example this does not pose a problem. But with a
lot of complex code involved I get a memory leak in some
circumstances - in particular, when I switch forms from a popup
commandbar that was created while on the main form.
This memory leak persists after I exit my app. However it is a
one off, ie having switched forms once in any given session of
Excel, no further leak occurs.
Switching forms from an OnTime macro does not appear to help.
Clearly there I'm doing something wrong and would appreciate
pointers.
TIA,
Peter T
'//Userform1 with 3 CommandButtons
Private Sub CommandButton1_Click()
Debug.Print "UF1 UserForm2 start"
Me.Hide
UserForm2.Show
Me.Show
Debug.Print "UF1 UserForm2 end"
End Sub
Private Sub CommandButton2_Click()
Debug.Print "UF1 run Proc1 start"
Proc1
Debug.Print "UF1 run Proc1 done"
End Sub
Private Sub CommandButton3_Click()
Debug.Print "Unload UF1"
Unload Me
End Sub
'// end Userform1
'//Userform2 with 1 CommandButton
Private Sub CommandButton1_Click()
Debug.Print "unload UF2 "
Unload Me
End Sub
'// end Userform2
'// in a normal module
Sub test()
UserForm1.Show
End Sub
Sub Proc1()
Debug.Print "Proc 1 start"
Proc2
Debug.Print "Proc 1 done"
End Sub
Sub Proc2()
Debug.Print "Proc 2 start"
Proc3
Debug.Print "Proc 2 done"
End Sub
Sub Proc3()
Debug.Print "Proc 3 start"
UserForm1.Hide
UserForm2.Show
'comes back here when UF2 unloads
UserForm1.Show
Debug.Print "Proc 3 done"
End Sub
'// end normal module