Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Question on ComboBox

  Asked By: Harry    Date: Nov 09    Category: MS Office    Views: 687
  

How can I add the objects to the ComboBox down list?
I see the Help and use AddItem("item1"), but I keep getting warning
messages, and the "item1" did not added to the down list of the
ComboBox.

I am new to Visual Basic.Anybody can help me? Thanks very much!

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Ida Andrews     Answered On: Nov 09

What do the warning messages say????????

 
Answer #2    Answered By: Lionel Thomas     Answered On: Nov 09

I create a Form with a combobox  inside. When I press the button the
Form will popup.
The problem is when I try to enter something in the combobox, there
is a Compile Error saying" Method or data member not found"
Here is my code:
Private Sub combo_Change()
Dim x As Integer
Set myBar = CommandBars.Add(Name:="Custom1", Position:=msoBarPopup,
Temporary:=False)

With combo
.Controls.Add Type:=msoControlButton, ID:=3
.Controls(1).Style = msoButtonCaption
.Controls.Add Type:=msoControlComboBox
With .Controls(2)

.Style = msoComboLabel
.AddItem ("1st item")
.AddItem ("2nd item")
.AddItem ("3rd item")
x = combo.ListCount
End With
End With
myBar.ShowPopup

combo.Value = x
End Sub

 
Answer #3    Answered By: Alejandro Smith     Answered On: Nov 09

... and what is your code??????

 
Answer #4    Answered By: Mena Schmidt     Answered On: Nov 09

I create a Form with a combobox  inside. When I press the button the
Form will popup.
The problem is when I try to enter something in the combobox, there
is a Compile Error saying" Method or data member not found"
Here is my code:
Private Sub combo_Change()
Dim x As Integer
Set myBar = CommandBars.Add(Name:="Custom1", Position:=msoBarPopup,
Temporary:=False)

With combo
.Controls.Add Type:=msoControlButton, ID:=3
.Controls(1).Style = msoButtonCaption
.Controls.Add Type:=msoControlComboBox
With .Controls(2)

.Style = msoComboLabel
.AddItem ("1st item")
.AddItem ("2nd item")
.AddItem ("3rd item")
x = combo.ListCount
End With
End With
myBar.ShowPopup

combo.Value = x
End Sub


I think I really need a combobox example to understand what the Help
talking about.

 
Answer #5    Answered By: Jessie Banks     Answered On: Nov 09

The basic  problem is that your code is trying to add  a popup menu to a
combobox. This does not make sense.

I suspect you do not want a commandbar at all. You probably just need to add
a button to the userform and make it visible when the combobox  item is
selected.


Perhaps a description of what the user will do and see would help  us
understand.

 
Answer #6    Answered By: Sam Evans     Answered On: Nov 09

I think I should start from the basic.So I just create a combo box
in the excel sheet and want to add  a default name
list, "A","B","C".The user can choose the name from the list  or
enter a new name in the box. The entered names will be stored in a
column, say, column A.

firstly, I try to add the name list "A", "B", "C" to the downlist of
the combobox. I write the following codes:

Private Sub ComboBox1_Change()
ComboBox1.Value = "cc"
ComboBox1.AddItem "A"
ComboBox1.AddItem "B"
ComboBox1.AddItem "C"
End Sub

When I come back to excel sheet, there is no name in the downlist of
the box.Only when I change the text of the box, the list come out. I
think my codes create a run-time downlist. Could you tell me how to
create a default unchanged name list?

 
Answer #7    Answered By: Gregg Bennett     Answered On: Nov 09

Two ways I can think of. One is to have a named range in the workbook
somewhere and set the RowSource to the name.

The other is to put your initialising code in the Workbook open event. (In
"This Workbook" in the VBE drop down the Left dropdown list  and select
"workbook" then the right drop down list and select open). This code will
fill the combobox  every time the workbook is opened.

Private Sub Workbook_Open()
With Worksheets("Sheet1").ComboBox1.
Value = "cc"
AddItem "A"
AddItem "B"
AddItem "C"
end with
End Sub

 
Didn't find what you were looking for? Find more on Question on ComboBox Or get search suggestion and latest updates.




Tagged: