PDA

View Full Version : Limiting User Entry on A Userform Combobox NOT working



simora
01-30-2017, 06:01 AM
Usually, Setting the Style property on a ComboBox using 2 - fmStyleDropDownList on an Excel Userform would stop the user from manually being able to enter data into that field, however, for some Excel 2007 Userforms that no longer works.
Does anyone know of Any workarounds or solutions to limit user input into the combobox field?

GTO
01-30-2017, 06:48 AM
How are you populating the combo box's .List? For me,


Private Sub UserForm_Initialize()
Me.ComboBox1.List = Array(1, 2, 3)
End Sub

...works and disallows other entries.

Mark

simora
01-30-2017, 07:34 AM
I was using a named range to populate the Combobox.
What I don't understand is that 2 - fmStyleDropDownList works for some of the forms, but not others.
They are all running in Excel 2007

GTO
01-30-2017, 07:40 AM
I am signing out, but could you post a workbook showing obfuscated data and one of the forms where the combo box is not workking?

simora
01-30-2017, 07:00 PM
I would love to, but its part of a huge process and I'm on the road right now. Back on Thursday.
I'll try to isolate the offending Userform then.

Thanks GTO

mikerickson
01-30-2017, 08:15 PM
This work-around comes to mind.

Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case vbKeyReturn, vbKeyTab
' do nothing, let the user Tab or Return out of the control
Case Else
' ignore all other keys pressed
KeyCode = 0
End Select
End Sub

simora
02-02-2017, 12:16 AM
I created a new sheet with an exact duplicate of the code, but I cannot replicate the problem.
2 - fmStyleDropDownList works as expected.

The problem has somehow become solved, and I still can't figure out why it didn't work as expected in the first place.
Thanks for all the suggestions & code.