Consulting

Results 1 to 3 of 3

Thread: Solved: Combobox: Enter, Tab and Backspace Keys Not Triggering Keypress Events

  1. #1

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

    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?

    [vba]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[/vba]

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

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

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Use the KeyDown or KeyUp events.

  3. #3
    Thanks again Kenneth!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •