+ Reply to Thread
Results 1 to 3 of 3

keydown in userform

Hybrid View

Undo keydown in userform 10-11-2021, 07:10 AM
romperstomper Re: keydown in userform 10-11-2021, 08:14 AM
6StringJazzer Re: keydown in userform 10-11-2021, 08:18 AM
  1. #1
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    927

    keydown in userform

    Hi

    within this code
    Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
        If KeyCode = 49 Then
        CommandButton1_Click
        End If
    End Sub
    it can be running everywhere in the userform1 content?
    or I must repeat it for every textbox and buttons?
    Last edited by Undo; 10-11-2021 at 07:13 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: keydown in userform

    You'd have to repeat it, assuming you never need to actually just type a 1 anywhere.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,999

    Re: keydown in userform

    The KeyDown event applies only to the control that has focus. If the userform has no controls, or all it's controls are disabled, it will apply to the userform. So yes, you would have to apply it to all textboxes and buttons.

    Please describe what you want to do and we might be able to come up with an alternate approach. You want the user to be able to press "1" and have it cause the same effect as clicking CommandButton1? One way to do this is to set the Accelerator property of the combobox to 1. Then you can click ALT+1 to click that button. It's not quite the same as clicking 1 but it's close.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. KeyDown not working when Userform is loaded from a module
    By dordar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2014, 07:56 AM
  2. Userform Combobox behavior on Keydown
    By bishope in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-12-2013, 03:24 PM
  3. Event keypress, tab or keydown and Setfocus
    By antoni in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2009, 10:55 PM
  4. Keydown rather then range
    By sgoldbe2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2008, 02:50 PM
  5. [SOLVED] Can I detect a KEYDOWN event while in a worksheet
    By Ken Soenen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2005, 09:20 PM
  6. Keydown and SelStart problem
    By jase in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2005, 09:50 AM
  7. Change date with KeyDown
    By John Pierce in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-09-2005, 10:40 AM
  8. keydown event
    By bfa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2005, 10:06 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1