+ Reply to Thread
Results 1 to 3 of 3

Capture KeyPress from anywhere in form

  1. #1
    Forum Contributor yay_excel's Avatar
    Join Date
    08-12-2011
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    190

    Question Capture KeyPress from anywhere in form

    Hello, I am trying to trigger the KeyPress event when a key is pressed anywhere in the form. It will work if I assign it to a command button for example and press the key while the button has focus but I need the form to detect the keypress when any control has focus. Does anyone know how to accomplish this?
    Last edited by yay_excel; 11-22-2011 at 02:42 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,164

    Re: Capture KeyPress from anywhere in form

    Hi,

    There is an event for UserForm_Keypress that you can capture when you press a key while the form itself has focus. You would need to create events for all the other controls on the form using keypress also.

    Depending on what your goal is, you could create a sub that tested where the keypress came from and branch accordingly. This sub would be the first downstream sub for all keypress events on all the controls on the form, including the form itself.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor yay_excel's Avatar
    Join Date
    08-12-2011
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    190

    Re: Capture KeyPress from anywhere in form

    Okay thank you, that's what I was afraid of. I will have to make events for every control on the form. It's not the KeyPress procedure that is complicated; I just didn't want to create an event for everything on the form as there are about 50 controls. Thank you for the answer though.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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