Results 1 to 8 of 8
  1. #1
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41

    run command button by keyboard

    hi all, i design a command button for add new record in a form, now how can i assign command button to "F2" keyboard, in the other words when i press "F2' from keyboard run Command248 :

    Private Sub Command248_Click()
    DoCmd.GoToRecord , , acNewRec
    End Sub



    thanks in advanced (sorry for my poor english)

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,818
    Did you search web?

    Instead of assigning function key could use the & in control caption to assign ALT shortcut key.
    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
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    You can assign various keyboard 'items' using an autokeys macro.
    One of only two macros I use (along with autoexec macro)

    For example in one database,
    a) ctrl+ shift +M is used to open the main menu form
    b) ctrl + F5 restarts the database at the login form
    C) ctrl+N opens Notepad

    Screenshot below shows some examples - note the {} around F2 etc, ^ is used for Ctrl, + denotes shift

    so ^+K is Ctrl+Shift+K; ^{F2} is Ctrl+F2

    Click image for larger version. 

Name:	Capture.PNG 
Views:	18 
Size:	8.8 KB 
ID:	33756

    The method has some restrictions. For example, you can't do Alt+ Q etc.
    Whether this is any use for your purposes is another matter
    Last edited by isladogs; 04-26-2018 at 06:49 PM. Reason: Added screenshot
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    hi, thanks ridders52 , i assign tow keyboards item form autokeys macro, but its not working for me, i assgined {f10} to close form and {f2} to run Command248 in form :


    but these not working in form, i created a function and use in autokeys macro.

    Function test()
    Call Command248_Click
    End Function
    Attached Thumbnails Attached Thumbnails uatokeys.png  

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    The function is behind a form. Any reference to the function from a location outside the form requires a prefix that locates the function.
    So, let's say the form containing the function is frmMine.
    The Runcode Function Name in the macro entry needs to be:
    FORM_frmMine.test()

    Also in order to be called by external code, the declaration for function test needs to be:
    Code:
    Public Function test()
        Call Command248_Click
    End Function

  6. #6
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    thanks a lot davegri, now it's only working but run macro and not working by press {f2} in form, i have to right click on macro and run to add new record.

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Hi
    Not sure from your answer whether it is now working or not.
    Note that AFAIK the macro MUST be called Autokeys or it won't work

    One thing to bear in mind that any shortcuts you use will overwrite standard Access keyboard shortcuts for that database.
    That's one reason why the Alt key can't be used in this approach.

    As both F2 & F10 are standard keyboard shortcut, I suggest you review their normal use and possibly change to CtrL+Shift+F2 or similar
    See this link for a full list: https://support.office.com/en-ie/art...5-3320fa6606e2
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    ridders52's assumption is correct. You need to rename Macro1 as AutoKeys

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

Similar Threads

  1. Replies: 3
    Last Post: 03-29-2015, 07:42 PM
  2. Replies: 1
    Last Post: 09-12-2014, 06:09 AM
  3. Command Button
    By Sierra Mike in forum Forms
    Replies: 14
    Last Post: 02-24-2014, 09:49 PM
  4. Replies: 3
    Last Post: 08-04-2013, 07:11 AM
  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