Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    How assign in a form, a function key to a command button.

    Function keys don't get enough credit, or use.
    I have a group of command buttons, that I would like to also assign function keys to, to do the same thing.
    One function key for each command button.
    i.e., help command button code can be invoked by f1. I don't want to globally assign, just for the current form.




    How can I do that without duplicating the action code?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Something like:

    CommandBars.ExecuteMso "Help"

    Not all of the function keys have use in Access. Exactly what are you trying to accomplish?
    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
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    Here's the why (because I want to)

    [QUOTE=June7;498824
    Not all of the function keys have use in Access. Exactly what are you trying to accomplish?[/QUOTE]

    I'm trying to make my forms "better" for the user, and eliminate inadvertent errors.
    And there are people like me that don't like being held hostage to a mouse, when there is a key right there waiting to be pressed.
    So I have a row of command buttons that look like this:
    (Dang, let's try again. I guess this forum software doesn't like cut and paste of images. Just like it doesn't want to replace selected text while editing.)
    And I'd like to know how to downsize the image it attaches after uploading (as if it isn't enough steps to go find and attach instead of just paste and resize.

    Click image for larger version. 

Name:	220805Functionkeys1.jpg 
Views:	24 
Size:	70.5 KB 
ID:	48451

  4. #4
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    And yes I know about "&" in the caption property, I want to press one key, not two.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    This is old but still might work and give you what you want

    https://bytes.com/topic/access/answe...n-keys-f12-etc

    EDIT - forgot to say you'd need to set Key Preview property for form to Yes if you want the form to take precedence. Otherwise I believe the key press will be associated with the control that has focus.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    How does this row of command buttons eliminate mouse click as well as two-key assignment with &?
    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.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I'd say the inference is that if you don't want to click the button with mouse, press the key identified by the button caption.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @ Micron Thanks, I'll check it out.
    See, this is why I like forums, lots of experience and nothing is really new. Someone saw something somewhere, that could take me hours to find even if I knew the correct terminology. BTW, I did search here and on Google before asking--came up empty handed.

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    BTW, I did search here and on Google before asking
    Would be nice if that was wide spread practice but based on a lot of questions I see, it's not. IMO it's worse when I post something with definitive terms and someone asks for an explanation instead of doing a bit of finger exercise.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Quote Originally Posted by June7 View Post
    How does this row of command buttons eliminate mouse click as well as two-key assignment with &?
    So now you want to get into the logic of mini/mainframes and the logical doings of dinosaurs like myself? Instead of accepting the new way of doing things, which is click on a 1mm2 button on the bottom of a form that might save unintended data changes (for example), why do I want to do this?

    I am being purposely snarky, but in a fun-loving way. Happy to discuss the design engineering, but not here. Actually more than happy because I would love to learn what objections others might have to my "old-school" way of presentation. Best with a WhatsApp or Skype video call. Teams is still giving me fits. Private message if interested in "being old-school-real in a conversation".

  11. #11
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,429
    which is click on a 1mm2 button on the bottom of a form that might save unintended data changes (for example
    so what is to stop someone clicking F2 by mistake?

    without duplicating the action code?
    Put the code in its own function

  12. #12
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    Nothing really...

    Quote Originally Posted by CJ_London View Post
    so what is to stop someone clicking F2 by mistake?


    Put the code in its own function
    But, as someone with ocular and motor disabilities, I'm sensitive to how others have to suffer with minuscule controls.
    Are you more likely to make an error on a big-fat command button, or with a 1mm2 control that sits next to three other such controls?

    Or make the f-key keystroke transfer to the code for the command button?

  13. #13
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    It's not always easy, thanks to M$ itself.

    Quote Originally Posted by Micron View Post
    ...IMO it's worse when I post something with definitive terms and someone asks for an explanation instead of doing a bit of finger exercise.
    It's not spot on point, but let me point out some error I made in syntax one day in this forum, about concatenating strings in VBA, and here is the sample from a M$ manual doing exactly what I did (using + instead of &):

    Click image for larger version. 

Name:	P1110500.jpg 
Views:	24 
Size:	127.8 KB 
ID:	48454

  14. #14
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Back to the original topic, here's how you program function keys as alternate to click on form button.

    twgon-Fkeys-davegri-v01.zip

    Clicking the button or pushing the function key produces the same result.

    Click image for larger version. 

Name:	twgocode.png 
Views:	26 
Size:	21.8 KB 
ID:	48456
    Last edited by davegri; 08-05-2022 at 06:04 PM. Reason: clarifying comment

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    It is not always wrong to concatenate with +. It just isn't always right or best. In cases, null + A = A whereas null & A = null, which is often not wanted. On my phone so keeping it short.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 10-09-2014, 03:06 PM
  2. How to assign a hotkey to a command button
    By tobydobo in forum Forms
    Replies: 5
    Last Post: 07-25-2013, 12:24 AM
  3. Assign F5 function to a button
    By eduardo in forum Forms
    Replies: 4
    Last Post: 06-24-2012, 08:21 AM
  4. Form command button to do something/call function
    By shubhamgandhi in forum Programming
    Replies: 2
    Last Post: 07-27-2011, 04:45 PM
  5. Replies: 1
    Last Post: 07-27-2010, 02:27 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