make userform in stnd by

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

make userform in stnd by

Post by sal21 »

I call a userform2 via commanbutton1 from other userform.
i use userform2.show
I use from userform2 a "x" in the top to close it or a commandbutton unload me.
But is possible to make in standby the userform2 without call the event UserForm_Initialize when i reclick on commanbutton1 of pricipal userform...

Sorry me for bad languge, i hope understand me:-)

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: make userform in stnd by

Post by HansV »

Yes. In the first place, make the command button hide the form instead of unload:

Code: Select all

Private Sub CommandButton1_Click()
  Me.Hide
End Sub
Because the form is hidden but not unloaded, next time you show the form, it is not initialized.

In the second place, you may want to prevent the users from closing the form through the "x" in the upper right corner:

Code: Select all

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  Cancel = (CloseMode = vbFormControlMenu)
End Sub
This disables closing through the "x" button, but not through a command button (or from Task Manager)
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

Re: make userform in stnd by

Post by sal21 »

HansV wrote:Yes. In the first place, make the command button hide the form instead of unload:

Code: Select all

Private Sub CommandButton1_Click()
  Me.Hide
End Sub
Because the form is hidden but not unloaded, next time you show the form, it is not initialized.

In the second place, you may want to prevent the users from closing the form through the "x" in the upper right corner:

Code: Select all

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  Cancel = (CloseMode = vbFormControlMenu)
End Sub
This disables closing through the "x" button, but not through a command button (or from Task Manager)
:thankyou: :clapping: