There can be a business case for the look of a form. That is - some controls are there some of the time, some times they are not there.
However, the essense of it is, IMHO, not whether they ARE there, but whether they are VISIBLE to the user. I do this fairly often. Depending on conditions, indeed, what they user
sees on the form can change.
So... this is a design issue. I use the .Visible property., and sometimes I dynamically change the size of the form so it looks better. If controls are no longer visible, I don't like big empty spaces where the invisible ones are.
Code:
Private Sub cmdHide_Click()
With frmBookmarks
.Height = 30
.Width = 140
.Top = 0
.Left = 300
End With
End Sub
Private Sub UserForm_Click()
If frmBookmarks.Top = 0 Then
MakeBigger
End If
End Sub
Sub MakeBigger()
With frmBookmarks
.Height = 166
.Width = 225
.StartUpPosition = 1
.Show
End With
End Sub
The above is an example where if the user clicks Hide, the form shrinks itself and moves itself to the top of the screen, showing just the title bar. If it is clicked there it resizes itself and put itself back to screen centre. As for resizing (with some controls visible, some not - depending on an input parameter), here is an example:
Code:
[COLOR=red]' in a public module[/color red]
Public strInput As String
Public strDump As String
Sub FormParameter()
strInput = LCase(InputBox("type in either Small or Big"))
UserForm1.Show
End Sub
[COLOR=red]' in the form code module[/color red]
Private Sub UserForm_Initialize()
Select Case strInput
Case "small"
Label1.Visible = False
TextBox1.Visible = False
Label2.Visible = False
TextBox2.Visible = False
Label3.Visible = False
ComboBox1.Visible = False
Label4.Visible = True
TextBox3.Visible = True
UserForm1.Height = 86
UserForm1.Width = 184
CommandButton1.Left = 120
CommandButton1.Top = 30
Case "big"
Label1.Visible = True
TextBox1.Visible = True
Label2.Visible = True
TextBox2.Visible = True
Label3.Visible = True
ComboBox1.Visible = True
Label4.Visible = False
TextBox3.Visible = False
UserForm1.Height = 140
UserForm1.Width = 205
CommandButton1.Left = 140
CommandButton1.Top = 70
Case Else
Msgbox "Input must be either ""small"" or ""big""."
strDump = "Dump me"
End Select
End Sub
Private Sub UserForm_Activate()
If strDump <> "" Then
Unload Me
End If
End Sub
This is of course VERY simplified. The controls are not created dynamically, but their visibility and location ARE. Notice the location of the command button moves, depending on whether the other controls are visible, or not. Also notice the error trap - if the user enter neither "small" or "big" UserForm_Initialize runs and passes something off to Activate (which runs
after), which dumps the form.
Needless to say, this could be done much better - I just wrote this quickly. But somethines there ARE reasons for have form controls dynamically useable. However, useability does not have to mean created.
Gerry