Run Sub using keyboard shortcut

jeffreyccs

New member
Local time
Yesterday, 16:39
Joined
Nov 10, 2012
Messages
29
Hi

In Excel it is very straightforward to execute a sub from a shortcut but in Access as far as I can see it is only possible to run a macro from a shortcut and from a macro only possible to execute a function rather than a sub.
As using a button is not practical I would like to find out if there is any other way to execute VBA code.

Any assistance would be much appreciated

Regards

Jeff
 
create a macro called AutoKeys macro.
you can assign a selected keyboards combination and call a function.
you can google it, like "ms access autokeys macro"

EDIT:

you can only Call Public Subs/Functions.
 
There should be no problem restating your sub as a function, the function does not need to return anything

function myFunction()
'do something
end function

as opposed to

function mySub()
'do something
end sub
 
Hi Jeff. Just curious, what does your Sub do and when do you need to run it? You don't need a macro or a button, if you use a Form to run it.
 
You can also use the form's properties key preview = Yes, and then code in the form's on key press event.
 
You can also use the form's properties key preview = Yes, and then code in the form's on key press event.

Doing that would be a nightmare. Every time the user types any key anywhere on the form, the code would run...repeatedly,
Much better to use the ampersand before a selected letter on the command button caption e.g. &Run as a keyboard shortcut
 
Doing that would be a nightmare. Every time the user types any key anywhere on the form, the code would run...repeatedly,
Much better to use the ampersand before a selected letter on the command button caption e.g. &Run as a keyboard shortcut
The way you described it, I agree, but I thought that that type of code could pick up more complex/intelligently designed combinations of keys, no? I honestly am asking...as I've rarely used that method. I always thought you could pick up one specific combination by checking the keyascii that got passed and if not exit sub. If that's correct, then that doesn't sound like a nightmare at all. If I'm wrong, I won't be surprised, as I've not gotten into that much at all.
I agree the button with the underlined Alt method, is awesome.
 
Yes you could use the key press method to respond to a specific keystroke only e.g. Ctrl+Shift+Q.
Indeed I use that approach in kiosk style applications
However its overkill for this purpose in my opinion.
 
My question is, why would the OP consider using a button "not practical?"
 
My question is, why would the OP consider using a button "not practical?"
Had to wonder the same thing as I read all the suggestions on how to do it with something that wasn't wanted. Yet a button provides a "no code" solution and the option to click on it or not. Then I suspected perhaps there is no form, just a need to run a routine at some point. The post ratio here is OP 1 to us 10 before me. Maybe it's jeffreyccs' turn?
 
Hi

Thanks for all the replies

Unfortunately I was unwell and could not reply earlier.

I will work through everything and let you know how I get on.

Many thanks

Regards

Jeff
 

Users who are viewing this thread

Back
Top Bottom