excel vba - UserForm Close button fails after form launched for second time -
i have userform
, a, command button opens userform
b using below code:
private sub cmd_click() me.hide b.show end sub
b, when closed via x button, runs following:
private sub userform_terminate() unload me a.show end sub
after:
- opening b (from a)
- closing b , returning
- and opening b again
the close button on b ceases work.
userform
menu form leads several others, navigating , forth between menus pretty basic requirement. behaviour reproducible every form linked a, tertiary forms open those.
given target demographic of older generation, want userforms
intuitive use, means preserving regular close button functionality.
does have info on this? may google-fu lacking, can't seem find has had same issue. input @ stage appreciated!
use variable refer 2nd userform
in first gives greater control on second forms status - can unset variable after have closed 2nd form , returned event handler instantiated in first place. guarantees each time click button launch userform2
working 'fresh copy'.
also should use queryclose
event - see msdn. event:
occurs before userform closes
you need able able control re-activation of userform1
before form disposed.
the terminate
event different:
occurs when references instance of object removed memory setting variables refer object nothing or when last reference object goes out of scope.
in sample code below getting correct behaviour using reference userform2
, handling queryclose
.
in sample code using userform1
, userform2
can substitue a
, b
in app:
code in userform1
:
option explicit private m_frm2 userform2 private sub commandbutton1_click() me.hide set m_frm2 = new userform2 m_frm2.show set m_frm2 = nothing end sub
code in userform2
:
option explicit private sub userform_queryclose(cancel integer, closemode integer) userform1.show unload me end sub
Comments
Post a Comment