PDA

View Full Version : Solved: Combobox: Enter, Tab and Backspace Keys Not Triggering Keypress Events



nameuser321
10-24-2012, 06:09 AM
Just creating a simple form that will allow me to select a name from a list located on another sheet. I load the combo box with the values in a named range. When I start to type the name the combo autofills based on my partial selection. When I attempt to capture the "Enter" key via the "_Keypress" sub no event is triggered. How can I capture the Enter, Tab and Backspace Keys?

Public Sub prepComboBox()
Dim arange As Range

fillComboBox Sheet1.ComboName, ThisWorkbook.Names("Headcount").RefersToRange
End Sub
Public Sub fillComboBox(aCombobox As ComboBox, arange As Range)
Dim aRow As Range
Dim index As Integer

index = 0
aCombobox.Clear
For Each aRow In arange.rows
If index <> 0 Then
aCombobox.AddItem (aRow.Cells(1, 2).value)
End If
index = index + 1
Next aRow
End Sub

This code is in the sheet with the combo box. (Triggers for every other key but 13

Private Sub ComboName_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
MsgBox "Key pressed"
End Sub

Kenneth Hobs
10-24-2012, 06:22 AM
Use the KeyDown or KeyUp events.

nameuser321
10-24-2012, 06:31 AM
Thanks again Kenneth!