User Forms with runtime controls

kcroom

New Member
Joined
Jan 4, 2012
Messages
3
I have a userform that asks the following-

Equipment Type: [ComboBox]
Qty: [TextBox]

I have the code that opens the form and all of the initial controls - it is rather long but this is basically what it looks like:

Private Sub UserForm_Initialize()

With ComboBox_BoilerType
.AddItem "Hydronic"
End With

ComboBox_BoilerType.ListIndex = 0

End Sub

I would like to take this information and have hidden controls become visible:

"Label-1" "TextBox-1"
"Label-2" "TextBox-2"
etc. up to number entered in QTY


I have no idea how to do this... any help would be greatly appreciated:)
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Well here is 1 way.
in the code below QTY_BX is the textbox name that the user keys the QTY into.

Code:
Private Sub CommandButton1_Click()
On Error goto ERRQTY
 
For i = 1 To QTY_BX
    For Each ctl In Me.Controls
        If TypeOf ctl Is MSForms.TextBox Then
              If ctl.Name Like "TextBox" & i Then
                ctl.Visible = True
              End If
         ElseIf TypeOf ctl Is MSForms.Label Then
            If ctl.Name Like "Label" & i Then
                ctl.Visible = True
            End If
        End If
    Next ctl
    
Next i
Exit sub
 
ERRQTY:
msgbox "No QTY entered"
 
End Sub
 
Upvote 0
What should the captions be for the labels?

Also how many label/textbox pairs will there be?

Is that based on the quantity entered in the textbox?
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top