Results 1 to 9 of 9
  1. #1
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47

    Question Keyboard shortcut to run a macro

    Hi all,

    I try to create a macro which is going to be activated by a keyboard shortcut, say Ctrl-Shift-x, then the code in module 1 will run.

    I tried the methods on the web, saw some videos, but they do not really help. i know how to create the same keyboard shortcut for macro to run in Excel, but access, i must seek help here.

    In the attached fileDatabase1.accdb, i tried to use autoKey to setup the keyboard shortcut to run sayHelloWorld in module 1, but the shortcut does not work, even if i run it by clicking the exclaimation mark button to run, it got error 2950 saying access can't find the code.



    Please help.

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    See the amended version attached
    I've changed your sub sayHelloWorld to a function and it now runs a message box
    The autokeys submacro needs to use RunCode not RunMacro
    I've changed the shortcut from Shift+Ctrl+X to Ctrl+W … as I'd managed to delete (cut) the module twice by mistake
    Attached Files Attached Files
    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

  3. #3
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47
    Thanks isladogs for your quick reply, unfortunately, for some reasons, may be access version problem, i can't open your file, could you also paste the code that you have changed in module 1 here please?

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    That's odd.
    I've converted it to mdb instead.
    Attached Files Attached Files
    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

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    One other point... The OP used the name AutoKey for the macro. It must be AutoKeys.
    Last edited by davegri; 12-31-2019 at 11:51 AM. Reason: sp

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Thanks Dave
    I forgot to mention that but did change it to Autokeys in both of my modified versions
    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

  7. #7
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47
    Thanks davegri, and thanks isladogs, I got the new file and it works, thanks, may i ask why use runcode instead of runmarco, i want to learn more, please tell me.

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    To run a saved macro you would indeed use RunMacro
    However module code procedures aren't macros
    So you have to use RunCode and the procedure has to be a function
    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

  9. #9
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47
    Now i understand, thanks isladogs, it is really a wonderful experience here to learn from you guys!

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

Similar Threads

  1. Replies: 3
    Last Post: 07-19-2017, 12:40 PM
  2. Keyboard Shortcut to Navigate to a Textbox
    By EddieN1 in forum Forms
    Replies: 3
    Last Post: 01-05-2015, 03:38 PM
  3. VBA Code to automatically activate keyboard shortcut
    By nygiantsfan in forum Programming
    Replies: 1
    Last Post: 07-08-2014, 11:45 AM
  4. Replies: 4
    Last Post: 06-08-2014, 11:53 AM
  5. Keyboard shortcut for Commenting
    By Ashe in forum Forms
    Replies: 1
    Last Post: 12-09-2011, 12:28 PM

Tags for this Thread

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