I am trying to add a combo box to a user form which will be created at run time , the problem I am facing is to add items to the combo box? Not able to figure out where the mistake would be. Thanks.
Function addComboBox(ByRef TempForm As Object, ByVal controlType As String,
ByVal pos As Integer, ByVal strCaption As String, ByVal strValues As String)
Dim NewComboBox As MSforms.ComboBox
Dim arr As Variant
Dim i As Integer
Set NewComboBox = TempForm.Designer.Controls.Add("forms.ComboBox.1")
arr = Split(strValues, ";")
With NewComboBox
.Name = strCaption & "_" & controlType & "_" & pos
.Top = 20 + (12 * pos)
.Left = 100
.Width = 150
.Height = 12
End With
For i = 0 To UBound(arr)
NewComboBox.AddItem arr(i)
Next i
End Function
Remove the word Designer
Try this (Tried And Tested)
FOLLOWUP
Try this. (TRIED AND TESTED)
SCREENSHOT
MORE FOLLOWUP
In such a scenario you have to check if the
UserForm_Initializeproc exists and then parse it. See the code below. I have added a new optional parameterSto your function. I am using that to place the combos one below the other.SCREENSHOT (Of Userform)
SCREENSHOT (Of Userform Code)