+ Reply to Thread
Results 1 to 5 of 5

arrow key as shortcut for userform button?

  1. #1
    Registered User
    Join Date
    04-28-2009
    Location
    UK
    MS-Off Ver
    Excel 2000
    Posts
    38

    arrow key as shortcut for userform button?

    I've made a userform with buttons to go to the next and previous record. I can allocate N and P as shortcuts using the Properties interface for the button. It'd be nice to use the arrow keys to navigate. But when I try to do that using the Properties box, it doesn't work.

    Is it possible to use an arrow key as a shortcut for a button or shortcut to call a subroutine?

    thanks in advance,
    David

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: arrow key as shortcut for userform button?

    The arrows keys will normally take you between the buttons, a bit like the Tab key.

    You can capture the KeyDown event and react to that.

    Userform with a Label and 2 buttons.
    CommandButton1 is for Previous
    CommandButton1 is for Next

    Please Login or Register  to view this content.
    Pressing the button simply updates the label.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    04-28-2009
    Location
    UK
    MS-Off Ver
    Excel 2000
    Posts
    38

    Re: arrow key as shortcut for userform button?

    Thank you. I'm learning more good techniques.

    I'll have to think harder about how to make this method work in a form with more than two buttons and a label. I added another button and a field. If the field has the focus, it doesn't respond to the arrow keys, and this technique gets stuck. Maybe I'm missing some obvious point. More than likely, considering that 2 weeks ago I know from nothing about VBA programming.

    thanks again,
    David

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: arrow key as shortcut for userform button?

    If the 2 movement controls are within a Frame then that will stop the arrow moving beyond the frame.

    Trouble is using the arrow keys in this way is not the standard practice for controls. So any work arounds may well have other drawbacks.

  5. #5
    Registered User
    Join Date
    04-28-2009
    Location
    UK
    MS-Off Ver
    Excel 2000
    Posts
    38

    Re: arrow key as shortcut for userform button?

    Quote Originally Posted by Andy Pope View Post
    ... Trouble is using the arrow keys in this way is not the standard practice for controls. So any work arounds may well have other drawbacks.
    Yes, I take your point. Maybe using the arrow keys wasn't such a bright idea after all ... but thanks for your solution anyway, it taught me some useful things.

    best wishes,
    David

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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