Results 1 to 9 of 9
  1. #1
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389

    why shortcut keys working without Alt key pressing

    hello everyone
    I have created some buttons on a form and in their format property I have created those shortcut key by adding & symbol in the caption which is activated by pressing alt+letter.
    The problem with this is that the button becomes active only by pressing the letter without pressing alt.


    Why is this happening.
    Thank you.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    a quick google of your question found a number of links such as this one

    https://stackoverflow.com/questions/...-windows-forms

    which explains why your buttons don't work as expected

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    That looks like it's for Windows forms and .Net?
    I dare say the problem has something to do with the reams of key events in OP's db. Once you go down that rabbit hole you can expect some trouble, especially if what you are trying to do is too advanced for your level.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    feels like this is a lot of complex work related to .net firmware. As far as I have understood, perhaps Micron is also trying to say the same, yet I have written this code to perform alt+m in the key down event of the form but it is not working.

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 18 And KeyCode = 77 Then
    Call Me.butadd
    End If
    End Sub

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by deepaksharma View Post
    feels like this is a lot of complex work related to .net firmware. As far as I have understood, perhaps Micron is also trying to say the same, yet I have written this code to perform alt+m in the key down event of the form but it is not working.

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 18 And KeyCode = 77 Then
    Call Me.butadd
    End If
    End Sub
    How can a keycode be both values????
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    I have placed this code in key down event of another button (for example button "abc") to click "butadd" button for shortcut key. Now this shortcut key is working perfect.
    But the problem is that this code works only when the user's focus is on the ABC button. Is there any way to which the user can be perform this code while keeping the focus on any part of the form.
    Thank you.

    Code:
    Private Sub abc_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case Shift
            Case acAltMask      'Alt pressed
            Select Case KeyCode
            Case 77
            Call butadd_Click       
    End Select
    End Select
    End Sub

  7. #7
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Greetings to everyone,

    I have watched a video on this link to solve this problem and have also seen a discussion related to shortcut keys on another link. In both the links, it is not clear why the shortcut key is being edited directly with the letter key without pressing the alt key and how it can be stopped.

    Is there any solution to this? If not, then the second method I have adopted of key down event works perfectly but in this method I am not able to underline any letter of the word written on the button through formatting ( So that the user can understand that on pressing this letter along with Alt key then this button will work as a shortcut key)
    What do you all have to say on this subject?
    Please provide proper guidance.

    video link - https://www.youtube.com/watch?v=pPonUGTKIf0
    Discussion Link - https://www.access-programmers.co.uk...ortcut.312507/

    My Method

    Code:
    Private Sub Form_Open(CANCEL As Integer)
    Me.KeyPreview = True
    End Sub
    
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case Shift
            Case acAltMask        'Alt pressed
                
                Select Case KeyCode
                    Case 77                          ' for one shortcut key
                        Me.butadd.SetFocus
                        Call butadd_Click
                        
                    Case 82                           ' for Second shortcut key
                        Me.butreg.SetFocus
                        Call butreg_Click
                        
                End Select
        End Select
        
    End Sub
    Thanks.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    To clarify what is being said.

    if the form or a control that does not accept input (such as a button) has the focus, you do not need to use the alt key. However if a control that can accept input (such as a textbox) has the focus then you do need to use the alt key so access knows not to include the subsequent letter as part of the control contents.

    so suggest create a visible textbox and
    1-set left, top, width & height to zero to effectively hide it
    2-ensure it is 1 in the tab order so it receives the focus when the form is opened (and/or set the focus to the control in the form open, load or current event)
    3-include controlname.setfocus at the end of each button click (or alternatively focus if that is where you have the code) event to return the focus to the 'visible' textbox

  9. #9
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by CJ_London View Post
    To clarify what is being said.

    if the form or a control that does not accept input (such as a button) has the focus, you do not need to use the alt key. However if a control that can accept input (such as a textbox) has the focus then you do need to use the alt key so access knows not to include the subsequent letter as part of the control contents.

    so suggest create a visible textbox and
    1-set left, top, width & height to zero to effectively hide it
    2-ensure it is 1 in the tab order so it receives the focus when the form is opened (and/or set the focus to the control in the form open, load or current event)
    3-include controlname.setfocus at the end of each button click (or alternatively focus if that is where you have the code) event to return the focus to the 'visible' textbox
    Thank you very much Cj_London,
    I can't praise your brain enough. Now this program is doing the trick perfectly. thank you so much.

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

Similar Threads

  1. How can i stop all shortcut keys on form
    By deepaksharma in forum Access
    Replies: 6
    Last Post: 10-24-2023, 01:28 AM
  2. Replies: 1
    Last Post: 06-11-2015, 06:15 AM
  3. Replies: 1
    Last Post: 01-06-2015, 06:29 AM
  4. Replies: 5
    Last Post: 03-15-2014, 05:27 PM
  5. Replies: 7
    Last Post: 01-28-2014, 04:52 PM

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