I’m new with VBA Programming, I have a
My problem is how to Auto size or adjust the form, Because I have hidden
Label, Now if I click the
Button it will unhide the
Label and also it will auto size the
Form and the other controls.
I don’t know how to start this.
Let’s assume there is hidden
Team Name and
Last Name now I click the update
RadioButton it will unhide the hidden
Texbox and adjust the form and other controls.
Is there any way to do this?
Say, the space required by the control Tbx hidden at the level 90pt from the top is 30pt. Therefore all controls below it should be moved down by 30pt when Tbx is made visible, and the form’s height also increased by that same measure. The code below would accomplish that while at the same time unhiding the control.
Dim Ctl As MSForms.Controls For Each Ctl In Me.Controls With Ctl If .Top >= 90 Then If .Visible = True Then .Top = Top + 30 Else .Visible = True End If End If End With Next Ctl Me.Top = Top + 30
Two things would be different in practice.
- You may have to hide the control again.
- Your would create the control on the fly rather than keep it hidden.
If you plan on hiding the control again you would need an array of all affected control names and another array (or dimension) for their existing Tops. You would loop through all the names in the array and reset the top, like,
Me.Controls(Arr(0, i)).Top = Arr(1, i) + Iif(HideMe, 0, 30)
Look into creating the control on the fly. You should be able to simply create a copy of an existing control from which it inherits all properties. Any event code for that control needs to be prepared in advance, however.