Philsophaie


The ComboBox1 doesn't initialize the list automatically. It only puts up a blank ComboBox . Here is the code I am using:

Private Sub Form1_Load()
ComboBox1.Items.Add ("Open App1")
ComboBox1.Items.Add ("Open App2")
ComboBox1.Items.Add ("Open App3")
ComboBox1.Items.Add ("Open App4")
End Sub




Re: ComboBox listing on Startup

Andy Pope


Hi,

You need to set either the value or listindex.
So to set the combobox to Open App3 either of these will do.


ComboBox1.Value = "Open App3"

or

ComboBox1.Listindex = 2






Re: ComboBox listing on Startup

Andy Pope

Also it may help if you but your code inside the Initialize event of the userform.

Code Snippet

Private Sub UserForm_Initialize()
With ComboBox1

.Items.Add ("Open App1")
.Items.Add ("Open App2")
.Items.Add ("Open App3")
.Items.Add ("Open App4")

.ListIndex =0

End With
End Sub








Re: ComboBox listing on Startup

Andy Pope

You have missed the Sub out of your code example

Code Snippet

Private SUB UserForm_Initialize()
ComboBox1.AddItem ("Open App1")
ComboBox1.AddItem ("Open App2")
ComboBox1.AddItem ("Open App3")
ComboBox1.AddItem ("Open App4")
End Sub







Re: ComboBox listing on Startup

Andy Pope

I see from your other postings that the control is not on a userform, which may explain the confusion.

As has been suggested you need to load the combobox from either Auto_Open routine or Workbook_Open event.

And it also helps everybody if you include links to your other posts.





Re: ComboBox listing on Startup

Philsophaie

When I type in manually 'Open App1' the other sub executes the additem but still no listing in the combobox.

Private Sub Auto_Open()
ComboBox1.AddItem ("Open App1")
ComboBox1.AddItem ("Open App2")
ComboBox1.AddItem ("Open App3")
ComboBox1.AddItem ("Open App4")
End Sub





Re: ComboBox listing on Startup

Andy Pope

The following placed in a standard code module will populate a combobox on sheet1 when the workbook opens.


Code Snippet

Sub Auto_Open()
Sheet1.ComboBox1.AddItem ("Open App1")
Sheet1.ComboBox1.AddItem ("Open App2")
Sheet1.ComboBox1.AddItem ("Open App3")
Sheet1.ComboBox1.AddItem ("Open App4")
End Sub








Re: ComboBox listing on Startup

MyLady

Hey,

Private Sub UserForm_Initialize()

ComboBox1.Style = fmStyleDropDownList

ComboBox1.AddItem "(Click DropButtonArrow to select)"

ComboBox1.AddItem "Open App1"

ComboBox1.AddItem "Open App2"

ComboBox1.AddItem "Open App3"

ComboBox1.AddItem "Open App4"

ComboBox1.ListIndex = 0

End Sub

Best Regards

Cathrine





Re: ComboBox listing on Startup

Philsophaie

Looking to have all of the additems to be displayed and selectable.

I can achieve this goal by substituting Auto_Open() by CommandButton_Click().

This is the most recent code:

Private Sub Auto_Open()

...

'need to Activate to enable the listing of ComboBox1.additem in the combobox window
...

With Worksheets("sheet1").ComboBox1
.Style = fmStyleDropDownList
.AddItem "Open App1"
.AddItem "Open App2"
.AddItem "Open App3"
.AddItem "Open App4"
.ListIndex = 0
End With

End Sub

Sub ComboBox1_Changed()

...'handle code

End Sub