PDA

View Full Version : Combo Box question



av8tordude
05-19-2009, 09:54 AM
I have a combo box that has only one option to select in the drop down field. I would like to accomplish 2 things...

1. When the combo box is focused, the drop down field automatically appear, therefore the user has the option to select the item in the drop down field.

2. Prevent the user from entering any text in the combo box, but force the user to select the item in the drop down field.

thank you in advance.

Bob Phillips
05-19-2009, 09:58 AM
1. Set the Listindex property to 0

2. set the Style property too 2 - fmStyleDropDownList

av8tordude
05-19-2009, 10:11 AM
1. Set the Listindex property to 0

2. set the Style property too 2 - fmStyleDropDownList

I fix the second one, but the first one I'm having difficulty finding. In the properties, there are only 3 items that have the word List...

ListRows
ListStyle
ListWidth

I don't see Listindex.

Bob Phillips
05-19-2009, 11:25 AM
You do that in code



Me.ComboBox1.ListIndex = 0

av8tordude
05-19-2009, 11:55 AM
Forgive my ignorance, but while accomplish the things you instructed, It still does not display the drop down field automatically when I select the combo box. I'm force to click the drop down arrow to display the drop down field. I was hoping that it would automatically display the drop down field when I click on the combo box.

Bob Phillips
05-19-2009, 11:58 AM
It does display it for me. But seeing as you only want one item, why use a combobox at all, a label would suffice.

av8tordude
05-19-2009, 12:05 PM
actually i have 2..."" & Filter. the "" is a blank item

av8tordude
05-19-2009, 12:07 PM
here is what I have...


Private Sub UserForm_Initialize()
Dim a
a = Array("","FILTER")
With Me.ComboBox1
.List = a
.ListIndex = 0
End With
End Sub

Bob Phillips
05-19-2009, 01:43 PM
Try



Private Sub UserForm_Initialize()
Dim a
a = Array("","FILTER")
With Me.ComboBox1
.List = a
.ListIndex = 1
End With
End Sub

av8tordude
05-19-2009, 02:34 PM
It still doesn't dispaly the drop down field automatically. I guess it must have something to do with my operating system or my excel version. :dunno Thanks anyways for your help XLD. I really appreciated it. :friends:

mikerickson
05-19-2009, 03:27 PM
You might try putting this in the userform's code module
Private Sub ComboBox1_Enter()
Rem requirement #1
ComboBox1.DropDown
End Sub

Private Sub ComboBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Rem requirement #2
KeyAscii = 0
End Sub

Bob Phillips
05-19-2009, 03:30 PM
This is exactly what it showed for me with that code

av8tordude
05-19-2009, 06:31 PM
Thank you both for the suggestions. I found this code on the net while searching for a solution.


Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const CB_SHOWDROPDOWN = &H14F

I had to change a few properties, but it comes close to what I trying to accomplish.