The following code when applied to the userform minimizes and maximizes the userform with the use of a toggle button. When the form is loaded it shows the maximized view of the form. & when the toggle button is clicked, it shows the minimized view.
How could the code be changed so that when the form is loaded, it shows only the minimized view and when the button is clicked it shows the maximized view.
Dim dHeight As Double
Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
Me.Height = Me.Height * 0.25
Else
Me.Height = dHeight
End If
End Sub
Private Sub UserForm_Initialize()
dHeight = Me.Height
End Sub
Any help would be kindly appreciated.
Thanks in advance.
Last edited by HansV on 15 May 2010, 11:26, edited 1 time in total.
Reason:to correct typo in subject (Minimze > Minimize)
Thank You Hans, for the help. I do really appreciate it. When I placed your line in my code and try to load the form it does not seem to load up. I did change the size or height of it.
What may be the reason for this?
What I’m trying to create is when the form is loaded , only the text boxes starting from First Name to the command buttons at the bottom of the from to be visible. And when I click the toggle button “Edit Record†the combo box and textbox Enter search parameter at the top to be visible.
How could I change the form accordingly to achieve this?
Workbook Uploaded for reference.
You do not have the required permissions to view the files attached to this post.
All declarations of variables and constants that are not local to a procedure or function must be placed at the top of the module. You placed the declaration of dHeight above the ToggleButton1_Click event procedure; that is not correct.
The userform will still not work, however, since your code refers to a text box txtRow that doesn't exist. And all defined names in your workbook are invalid.
All declarations of variables and constants that are not local to a procedure or function must be placed at the top of the module. You placed the declaration of dHeight above the ToggleButton1_Click event procedure; that is not correct.
on the form in the attached workbook I have assigned a toggle button in order to minimize and maximize the user form. What I'm trying to do is when the user form is loaded only the first combo box, text box and the list box to be visible with the buttons in the user form.
When I click the edit button; the form to display the text boxes and combo boxes below the form by maximizing the form.
Any advice on how to do the above mentioned with the code posted in the beginning of this thread would be kindly appreciated.
You do not have the required permissions to view the files attached to this post.
If you reduce the height of the form, the Edit button will be hidden, so the user won't be able to click it.
You should move the Edit button to the top of the form (first make room for it by making the combo box and text box less wide and moving the text box a bit to the left).
Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
Me.Height = Me.ListBox1.Top + Me.ListBox1.Height + 30
Else
Me.Height = dHeight
End If
End Sub
You may have to experiment a bit with the value 30 to get it right.
Thanks for the help Hans. Your code works just as I was assuming.
By the way I wonder if the form code could be adjusted so that 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.
Any help of how to do this would be kindly appreciated.
The attached workbook does provide such an example.
You do not have the required permissions to view the files attached to this post.
Private Sub TogEdit_Click()
If TogEdit.Value = True Then
Me.Height = Me.ListBox1.Top + Me.ListBox1.Height + 30
TogEdit.Visible = False
Else
Me.Height = dHeight
End If
End Sub
hoping that when the toggle button is clicked it gets hidden and the rest of the form gets visible. But, The code is not effective as the toggle button is already clicked when the userform is loaded.
How could I overcome this? Any suggestion would be kindly appreciated.