Minimize & maximize userform with toggle button

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Minimize & maximize userform with toggle button

Post by adam »

I've uploaded the workbook with modified code for reference. When the userform is loaded only button that is visible is the Edit Toggle button. When the toggle button is clicked the rest of the text boxes are visible. But the toggle button does not get hidden. and the label (now assigned) to the form does not get visible.

I would be happy if I'm told what I have done wrong in here.
You do not have the required permissions to view the files attached to this post.
Best Regards,
Adam

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

Re: Minimize & maximize userform with toggle button

Post by HansV »

In the first place, you have lines

Me.Label10 = True

and

Me.Label10 = False

These lines don't show/hide the label but change its caption. You should set the Visible property of the label to True/False instead.

And you have switched the lines that set the height of the form; it should be the other way round.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Minimize & maximize userform with toggle button

Post by adam »

Is this how the initialize code

Code: Select all

Private Sub UserForm_Initialize()
Me.txtRow = 1
UpdateData
CboSearchBy.List = Array("Customer ID", "Name", "Address")
cboSex.List = Array("Male", "Female")
cboComments.List = Array("New", "Old")
dHeight = Me.Height
Me.TogEdit = True
Me.Label10 = True / False
End Sub
And the toggle button code should be?

Code: Select all

Private Sub TogEdit_Click()
  If TogEdit.Value = True Then
    Me.Height = Me.ListBox1.Top + Me.ListBox1.Height + 70
    TogEdit.Visible = False
  Else
    Me.Height = dHeight
  End If
End Sub
Best Regards,
Adam

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

Re: Minimize & maximize userform with toggle button

Post by HansV »

The line

Me.Label10 = True / False

will cause an error, for False = 0 so you're trying to divide by 0. As mentioned in my previous reply, you should set the Visible property of the label. You can do this in TogEdit_Click.

In Userform_Initialize, I'd replace

Me.TogEdit = True

with

Call TogEdit_Click.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Minimize & maximize userform with toggle button

Post by adam »

Here is how the Userform_Initialize, has been replaced

Code: Select all

Private Sub UserForm_Initialize()
Me.txtRow = 1
UpdateData
CboSearchBy.List = Array("Customer ID", "Name", "Address")
cboSex.List = Array("Male", "Female")
cboComments.List = Array("New", "Old")
dHeight = Me.Height
Call TogEdit_Click
End Sub
And here is how the Me.Label10 is set to the Visible property in TogEdit_Click.

Code: Select all

Private Sub TogEdit_Click()
  If TogEdit.Value = True Then
    Me.Height = Me.ListBox1.Top + Me.ListBox1.Height + 70
    TogEdit.Visible = False
    Me.Label10 = Visible
  Else
    Me.Height = dHeight
  End If
End Sub
when the form is opened, as mentioned before the combobox, list box and text box will be visible with the toggle button just below the listbox.
And when the toggle button is clicked it disappears and the remaining text boxes together with the command buttons are made visible in the form.
The above codes does open the form with the toggle button clicked but does not perform as above Instead it does the opposite. Meaning when the toggle button is clicked the form minimizes instead of maximizing.
Best Regards,
Adam

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

Re: Minimize & maximize userform with toggle button

Post by HansV »

adam wrote:The above codes does open the form with the toggle button clicked but does not perform as above Instead it does the opposite. Meaning when the toggle button is clicked the form minimizes instead of maximizing.
Yes, I mentioned that in Post=16748 earlier today. You have to switch the lines that set the height.

Moreover, the line

Me.Label10 = Visible

does *not* set the Visible property of the label. Look at the line above it to see how it should be done.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Minimize & maximize userform with toggle button

Post by adam »

Hans, Finally I have made out something with your help. Please let me know this is what you had been advising.
Thanks in advance.

This form does everything I had been asking for. Except the toggle button appears as clicked when the userform is loaded.
You do not have the required permissions to view the files attached to this post.
Best Regards,
Adam

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

Re: Minimize & maximize userform with toggle button

Post by HansV »

In TogEdit_Click, change

If TogEdit.Value = True Then

to

If TogEdit.Value = False Then

and in UserForm_Initialize, change

Me.TogEdit = True

to

Call TogEdit_Click

as I suggested earlier in this thread.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Minimize & maximize userform with toggle button

Post by adam »

Thankyou Hans. Now I can relax & watch my TV show. Workbook works excellent now.
Best Regards,
Adam