I'm trying to solve an issue with a combo box, where I don't want the listed options to create another double every time the macro is executed, which happens if the AddItem property is only used to populate the combo box. The project is to list 12 months in a dropdown menu within a user form, with the goal being to let the user display that table in print preview mode (the accompanying worksheet has a table for each month). I wrote a string array for the months and then told it to populate the combo box with the AddItem property in a loop. To wit:
Private Sub ComboBox1_Change()
Dim strMonth(0 To 11) As String
strMonth(0) = "Print April Table"
strMonth(1) = "Print May Table"
strMonth(2) = "Print June Table"
strMonth(3) = "Print July Table"
strMonth(4) = "Print August Table"
strMonth(5) = "Print September Table"
strMonth(6) = "Print October Table"
strMonth(7) = "Print November Table"
strMonth(8) = "Print December Table"
strMonth(9) = "Print January Table"
strMonth(10) = "Print February Table"
strMonth(11) = "Print March Table"
Dim mthPosition As Long
For mthPosition = LBound(strMonth) To UBound(strMonth)
UserForm13.ComboBox1.AddItem strMonth(mthPosition)
Next mthPosition
With UserForm13.ComboBox1
.Style = fmStyleDropDownList
End With
UserForm13.Show
End Sub
For some reason, I get an error at the AddItem line saying that VBA could not find the specified object, even though the path is specified... the same thing happens if the code is run under a routine for the ComboBox or tested in a separate routine.
I appreciate your help in this respect.
UserForm13and that the combo box on it is actually calledComboBox1?