Results 1 to 10 of 10
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Key Down event does not fire

    I haven't been able to determine why the Key Down event won't fire. I use the Access Switchboard form in the current case and want to add some functionality triggered by holding down the Alt key, but can't get the event to fire. (test code below) Any ideas?



    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    MsgBox "KeyDown event fired"
    If KeyCode = acAltMask Then MsgBox "acAltMask key pressed"
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Since Alt and Ctrl are intended to perform in conjunction with other keys, I would not expect either to trigger event on their own.

    Pressing Alt key long enough displays shortcut keys on the ribbon. Buttons on form set up with shortcut can be accessed with Alt+ltr.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Explaining further, my OP should have indicated that the Alt key would be used in conjunction with a mouse click on one of the Switchboard items.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In a brief test, the form level event didn't work for me until the form's Key Preview property was Yes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Okay, the event fires okay, but what's the key code for the Alt key, apparently NOT acAltMask!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
      Debug.Print KeyCode
    End Sub
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Smarty-pants
    Yes, it's value is 18 (Shift = 1 + Alt = 7)
    But I couldn't find the Access constant for that key.
    There's more to be said about this caper and I'll get back a bit later.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Okay, learning something new.

    Event does fire with the Alt and Ctrl keys with KeyPreview Yes.

    Alt is 18 and Ctrl is 17. Possibly these do not have ac constants. Do other keys? Check out the VBA Editor Object Browser for Access intrinsic constants and look at the vbKey___ list.

    Your code is using acAltMask with the wrong argument parameter.

    If Shift = acAltMask Then MsgBox "Alt key pressed"

    Review
    Intrinsic constants as bit masks | Microsoft Learn
    Access VBA bit masking in KeyDown Event - Stack Overflow
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    The key constant for the ALT key is vbKeyMenu. Not sure the thinking behind the choice, but at least now happy to know what it is.
    Thanks All,
    Bill

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    As I recall when testing, the ALT key was toggling menu choices on and off. Computer is off so can't test right now.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. OnPage event doesn't seem to fire
    By GraeagleBill in forum Reports
    Replies: 14
    Last Post: 09-11-2022, 01:20 PM
  2. Wondering Why On Change Event Won't Fire
    By lccrews in forum Programming
    Replies: 7
    Last Post: 07-13-2018, 04:35 PM
  3. Combo Box On Click Event does not fire
    By GraeagleBill in forum Forms
    Replies: 7
    Last Post: 10-30-2015, 01:20 PM
  4. Fire off event on another form
    By Ruegen in forum Access
    Replies: 4
    Last Post: 04-12-2015, 11:50 PM
  5. Trying to fire event on record change
    By danielhowden in forum Forms
    Replies: 3
    Last Post: 05-13-2011, 06:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums