Keyboard Shortcuts to Execute Code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3655

    Keyboard Shortcuts to Execute Code?

    Hey Friends,

    MS Access 2010.

    Does anyone know of a way to execute Code (or even a Macro) by using a Keyboard Shortcut? For example, if I have a block of Code (or a Macro) that were to check for new data updates (or ANYTHING--that is just a "fer example"), but I wanted to be able to execute it from anywhere within a Project (and at any time) by simply hitting, for example, Ctrl-Shift-Q.

    I'm just exploring new ideas and possibilities, and this one came to mind as potentially being very useful for what I want to do.

    Thank for all your hepp!
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    I don't know of a way to set a program level keyboard shortcut like that, but you can use the KeyUp event on each form to call your code. Just set the form's Key Preview property to Yes and test for the key code combination.

    Code:
    If (Shift And acCtrlMask) > 0 And (Shift And acShiftMask) > ) And KeyCode = vbKeyQ Then

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3655

      #3
      This assumes a Form is open and with the focus. It seems like a potential option. I'm looking for anytime the DB is opened, with no forms being open (i.e., if the Back End is opened), such that I could run code to take away Navigation Pane and override the ByPass Key, but, then still be allowed to reverse it, all using shortcut keys.

      Hmmmmmmmmmmmmm. .

      Thanks, Seth!

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        I just found out how. Create a macro called AutoKeys. Give it a submacro with the name of the submacro being your key combination (^ for Ctrl, + for Shift) and have its action be whatever you need. This is called AutoKeys if you want to google it. I got it to work with Ctrl + Q, but I couldn't get Ctrl + Shift + Q to work. You may have to play with that.

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          Just got the Ctrl + Shift + Q key combination to work. Enter +^{Q} as the submacro name.

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3655

            #6
            I'll play around with it a bit. Thanks for the info!

            Comment

            • twinnyfo
              Recognized Expert Moderator Specialist
              • Nov 2011
              • 3655

              #7
              Seth,

              You are absolutely THE MAN!!!! This is the coolest thing I've discovered yet. Now, when I want to protect my data files, I just run a shortcut key macro that removes the nav pane, disallows the bypass key and prevents all the menus, then I close the DB and VOILA!! To unlock it all, I just execute another shortcut key!

              Yes, I am sure there are still ways to get around it, but most people will just simply get discouraged and walk away when all they see is an absolutely blank Access DB window.

              Thanks so much, Seth! I'll put this into every DB I create from now on!

              Comment

              • Seth Schrock
                Recognized Expert Specialist
                • Dec 2010
                • 2965

                #8
                I might put it in my apps too, but as a user tool to open specific forms from anywhere. Thanks for making me think to look for an answer like that :)

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32645

                  #9
                  Nice catch Seth. AutoKeys (Run an Access macro by using a keyboard shortcut) macro it is.

                  NB. I typed this up the other day but never got to post it :-(
                  Last edited by NeoPa; Apr 3 '15, 03:25 AM.

                  Comment

                  • Seth Schrock
                    Recognized Expert Specialist
                    • Dec 2010
                    • 2965

                    #10
                    I read that article when I was looking into the topic. However, Access 2010 (and 2013 I think) are very different in how Macros are built, so that article didn't help me build the macro. I'll see if I can find what article I used.

                    Here is the link that told me how to do it: autokeys 2010
                    Last edited by Seth Schrock; Apr 3 '15, 01:05 PM. Reason: Provided link

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32645

                      #11
                      I'm a little confused by that Seth. It may well be that the way to create macros is somewhat changed, but the explanation for what is required within the macro hasn't.

                      John Viescas (is very clever actually.) tells how to set up the macro originally and includes a couple of examples for specific keys, but only the other link gives a good reference of what to use to do what across the board. The details for that haven't changed for many versions as far as I can tell.

                      Comment

                      • Seth Schrock
                        Recognized Expert Specialist
                        • Dec 2010
                        • 2965

                        #12
                        You are correct that what is required within the macro is the same, but the creation is very different and I couldn't get to the content stage with just what was in your link. Part of it is that it doesn't explain what it is trying to do, so I couldn't figure out how to do that in the new version.

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32645

                          #13
                          Well, both links are available now and you found your answer in the end so we're all good and well done :-)

                          Comment

                          Working...