Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Attaching shortcut key to form buttons (XP)

    Is there a way to attach a shortcut key to a form button? For example, can I make CTRL + A do the same thing as clicking on an Add button? I know within Excel, a macro can have a shortcut key, and within in windows menus, shortcuts are attached, but can that be extended to form buttons?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Attaching shortcut key to form buttons (XP)

    The simplest way is to use an ampersand & in the caption of the button: &Add will look like Add, indicating that Alt+A is the shortcut key.

    Alternatively, you can set the KeyPreview property of the form to Yes, and check keystrokes in the KeyDown (or KeyUp) event of the form. You can't use the KeyPress event here, because you can't check for Ctrl there.

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Shift = acCtrlMask And KeyCode = vbKeyA Then
    cmdAdd_Click
    End If
    End Sub

  3. #3
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching shortcut key to form buttons (XP)

    DUH. Boy is my brain fried! I've done this in Excel - I don't know why I wasn't making the connection in Access. Thank you for your help in Access 101. I am now searching for the paper bag to put over my head.

  4. #4
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Attaching shortcut key to form buttons (XP)

    Here's a few you can have....

    <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  5. #5
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching shortcut key to form buttons (XP)

    Thanks Mark. It's nice knowing that no matter what is needed, someone is always out there to help. The Wal-Mart bags just weren't doing the trick.

  6. #6
    Star Lounger
    Join Date
    Aug 2002
    Location
    Des Moines, Iowa, USA
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching shortcut key to form buttons (XP)

    Hans, I forgot to thank you for the extra item included in your response where you set up the Key Preview property and check the keystrokes in the KeyDown (or KeyUp) event. This may come in handy for my one "schitzophrenic" button which can either add or update a record, depending upon the "mode" of the form. The button has no caption until the mode is determined, so no shortcut exists. Thanks again

Posting Permissions

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