By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Running procedure when I press Ctl K

P: n/a
I want to run an event when I press the Ctl key simultaneously with the K
key. How do I achieve this in VBA?

dixie
Nov 13 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi, Dixie.

You can create a macro that will call a VBA function every time you hit a
certain key combination. Search Access Help for "AutoKeys."

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"dixie" <di****@dogmail.com> wrote in message
news:lO***************@nnrp1.ozemail.com.au...
I want to run an event when I press the Ctl key simultaneously with the K
key. How do I achieve this in VBA?

dixie

Nov 13 '05 #2

P: n/a
I know that 69 Camaro, but it is a bit too open in a macro. I want to do it
in vba within a module if I can.

dixie

"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote in
message news:bZt0d.744$bj2.108@trnddc08...
Hi, Dixie.

You can create a macro that will call a VBA function every time you hit a
certain key combination. Search Access Help for "AutoKeys."

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"dixie" <di****@dogmail.com> wrote in message
news:lO***************@nnrp1.ozemail.com.au...
I want to run an event when I press the Ctl key simultaneously with the K key. How do I achieve this in VBA?

dixie


Nov 13 '05 #3

P: n/a
I forgot to mention that you can also use the KeyDown( ) event on a form to
determine which keys where pressed, and if they are the correct combination,
then the KeyDown( ) event can execute your VBA procedure. However, this
will only be effective in the current form, whereas the AutoKeys macro will
be global and can be used for all database objects.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote in
message news:bZt0d.744$bj2.108@trnddc08...
Hi, Dixie.

You can create a macro that will call a VBA function every time you hit a
certain key combination. Search Access Help for "AutoKeys."

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"dixie" <di****@dogmail.com> wrote in message
news:lO***************@nnrp1.ozemail.com.au...
I want to run an event when I press the Ctl key simultaneously with the K key. How do I achieve this in VBA?

dixie


Nov 13 '05 #4

P: n/a
So how do I tell it that Ctrl K has been pressed. If I can find that out, I
can work the rest out for myself (hopefully).

dixie

"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote in
message news:gbu0d.761$bj2.431@trnddc08...
I forgot to mention that you can also use the KeyDown( ) event on a form to determine which keys where pressed, and if they are the correct combination, then the KeyDown( ) event can execute your VBA procedure. However, this
will only be effective in the current form, whereas the AutoKeys macro will be global and can be used for all database objects.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote in message news:bZt0d.744$bj2.108@trnddc08...
Hi, Dixie.

You can create a macro that will call a VBA function every time you hit a
certain key combination. Search Access Help for "AutoKeys."

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"dixie" <di****@dogmail.com> wrote in message
news:lO***************@nnrp1.ozemail.com.au...
I want to run an event when I press the Ctl key simultaneously with
the K key. How do I achieve this in VBA?

dixie



Nov 13 '05 #5

P: n/a
Here's a little bit of code added to the example in Access Help for the
KeyDown event to show how to determine whether the correct keys were
pressed:

Private Sub KeyHandler_KeyDown(KeyCode As Integer, _
Shift As Integer)
Dim intShiftDown As Integer, intAltDown As Integer
Dim intCtrlDown As Integer

' Use bit masks to determine which key was pressed.

intShiftDown = (Shift And acShiftMask) > 0
intAltDown = (Shift And acAltMask) > 0
intCtrlDown = (Shift And acCtrlMask) > 0

' Display message telling user which key was pressed.

If (intShiftDown And (Chr(KeyCode) = "k")) Then
MsgBox "You pressed the SHIFT key and the " & _
Chr(KeyCode) & " key."
End If

If (intAltDown And (Chr(KeyCode) = "k")) Then
MsgBox "You pressed the ALT key and the " & _
Chr(KeyCode) & " key."
End If

If (intCtrlDown And (Chr(KeyCode) = "k")) Then
MsgBox "You pressed the CTRL key and the " & _
Chr(KeyCode) & " key."
End If
End Sub

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"dixie" <di****@dogmail.com> wrote in message
news:ic****************@nnrp1.ozemail.com.au...
So how do I tell it that Ctrl K has been pressed. If I can find that out, I can work the rest out for myself (hopefully).

dixie

"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote in message news:gbu0d.761$bj2.431@trnddc08...
I forgot to mention that you can also use the KeyDown( ) event on a form to
determine which keys where pressed, and if they are the correct

combination,
then the KeyDown( ) event can execute your VBA procedure. However, this
will only be effective in the current form, whereas the AutoKeys macro

will
be global and can be used for all database objects.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote

in
message news:bZt0d.744$bj2.108@trnddc08...
Hi, Dixie.

You can create a macro that will call a VBA function every time you hit a
certain key combination. Search Access Help for "AutoKeys."

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a

message will be forwarded to me.)
"dixie" <di****@dogmail.com> wrote in message
news:lO***************@nnrp1.ozemail.com.au...
> I want to run an event when I press the Ctl key simultaneously with

the
K
> key. How do I achieve this in VBA?
>
> dixie
>
>



Nov 13 '05 #6

P: n/a
Hi Dixie,

I tried the code segment offered by 69camaro and couldn't make it work, it
didn't seem to recognize the Chr(KeyCode) = "k") logic. I ended up with
something very simplistic but it may be a place to start. Recognizing a
keyhit on a form rather than a control:

' must set form key preview event = yes
Private Sub Form_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub

This event will be triggered when hitting any key while the form has focus.
I tried SHIFT 'a' (i.e. uppercase A) and got 65, tried 'a' (i.e. lowercase
a) and got 97, tried CONTROL 'a' and got 1. CONTROL 'k' yields 11.

HTH -Linda

"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote in
message news:1Nu0d.1048$MS1.585@trnddc02...
Here's a little bit of code added to the example in Access Help for the
KeyDown event to show how to determine whether the correct keys were
pressed:

Private Sub KeyHandler_KeyDown(KeyCode As Integer, _
Shift As Integer)
Dim intShiftDown As Integer, intAltDown As Integer
Dim intCtrlDown As Integer

' Use bit masks to determine which key was pressed.

intShiftDown = (Shift And acShiftMask) > 0
intAltDown = (Shift And acAltMask) > 0
intCtrlDown = (Shift And acCtrlMask) > 0

' Display message telling user which key was pressed.

If (intShiftDown And (Chr(KeyCode) = "k")) Then
MsgBox "You pressed the SHIFT key and the " & _
Chr(KeyCode) & " key."
End If

If (intAltDown And (Chr(KeyCode) = "k")) Then
MsgBox "You pressed the ALT key and the " & _
Chr(KeyCode) & " key."
End If

If (intCtrlDown And (Chr(KeyCode) = "k")) Then
MsgBox "You pressed the CTRL key and the " & _
Chr(KeyCode) & " key."
End If
End Sub

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"dixie" <di****@dogmail.com> wrote in message
news:ic****************@nnrp1.ozemail.com.au...
So how do I tell it that Ctrl K has been pressed. If I can find that out,
I
can work the rest out for myself (hopefully).

dixie

"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote

in
message news:gbu0d.761$bj2.431@trnddc08...
I forgot to mention that you can also use the KeyDown( ) event on a form
to
determine which keys where pressed, and if they are the correct

combination,
then the KeyDown( ) event can execute your VBA procedure. However,
this will only be effective in the current form, whereas the AutoKeys macro

will
be global and can be used for all database objects.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message will be forwarded to me.)
"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM>

wrote in
message news:bZt0d.744$bj2.108@trnddc08...
> Hi, Dixie.
>
> You can create a macro that will call a VBA function every time you hit
a
> certain key combination. Search Access Help for "AutoKeys."
>
> HTH.
>
> Gunny
>
> See http://www.QBuilt.com for all your database needs.
> See http://www.Access.QBuilt.com for Microsoft Access tips.
>
> (Please remove ZERO_SPAM from my reply E-mail address, so that a

message > will be forwarded to me.)
>
>
> "dixie" <di****@dogmail.com> wrote in message
> news:lO***************@nnrp1.ozemail.com.au...
> > I want to run an event when I press the Ctl key simultaneously

with the
K
> > key. How do I achieve this in VBA?
> >
> > dixie
> >
> >
>
>



Nov 13 '05 #7

P: n/a
"dixie" <di****@dogmail.com> wrote in message news:<lO***************@nnrp1.ozemail.com.au>...
I want to run an event when I press the Ctl key simultaneously with the K
key. How do I achieve this in VBA?

dixie


You need to create a macro and save the macro as autokeys.
In the macro use the macro name e.g. {F9} so that the macro will run
when F9 is pressed.
The macro then then run the code you want.
Alex
Nov 13 '05 #8

P: n/a
Hi, Linda.
I tried the code segment offered by 69camaro and couldn't make it work, it
didn't seem to recognize the Chr(KeyCode) = "k") logic.
I that suspect you were trying to use the example on an object other than a
control that accepts keyboard input. I tested the code on Access 97, 2K,
and '03, and they all worked perfectly, so I didn't have any reason to
suspect that this example wouldn't also work in Access XP.

Try opening a form in Design View, then create a text box named KeyHandler
(as provided in Microsoft's example from Help), then paste the code I
offered in my previous post into the form's module. Save and compile.

If Access doesn't automatically set the "On Key Down" event property to
[Event Procedure], then set it manually with your mouse, and make sure that
the name of the control is KeyHandler. (If Access creates a new event
procedure instead of opening the module at the code you pasted in, then
either the text box name is misspelled or the wrong event has been selected
with the mouse.) Save the form again if you made changes.

Open the form in Form View. Now hold down either the <CTRL>, <SHIFT>, or
<ALT> key down, then press the <k> key and see whether the message box pops
up telling you which keys you pressed.

Please post back if you have further problems.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"Squirrel" <wi*****@covad.net> wrote in message
news:b3**************************@msgid.meganewsse rvers.com... Hi Dixie,

I tried the code segment offered by 69camaro and couldn't make it work, it
didn't seem to recognize the Chr(KeyCode) = "k") logic. I ended up with
something very simplistic but it may be a place to start. Recognizing a
keyhit on a form rather than a control:

' must set form key preview event = yes
Private Sub Form_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub

This event will be triggered when hitting any key while the form has focus. I tried SHIFT 'a' (i.e. uppercase A) and got 65, tried 'a' (i.e. lowercase
a) and got 97, tried CONTROL 'a' and got 1. CONTROL 'k' yields 11.

HTH -Linda

"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote in message news:1Nu0d.1048$MS1.585@trnddc02...
Here's a little bit of code added to the example in Access Help for the
KeyDown event to show how to determine whether the correct keys were
pressed:

Private Sub KeyHandler_KeyDown(KeyCode As Integer, _
Shift As Integer)
Dim intShiftDown As Integer, intAltDown As Integer
Dim intCtrlDown As Integer

' Use bit masks to determine which key was pressed.

intShiftDown = (Shift And acShiftMask) > 0
intAltDown = (Shift And acAltMask) > 0
intCtrlDown = (Shift And acCtrlMask) > 0

' Display message telling user which key was pressed.

If (intShiftDown And (Chr(KeyCode) = "k")) Then
MsgBox "You pressed the SHIFT key and the " & _
Chr(KeyCode) & " key."
End If

If (intAltDown And (Chr(KeyCode) = "k")) Then
MsgBox "You pressed the ALT key and the " & _
Chr(KeyCode) & " key."
End If

If (intCtrlDown And (Chr(KeyCode) = "k")) Then
MsgBox "You pressed the CTRL key and the " & _
Chr(KeyCode) & " key."
End If
End Sub

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"dixie" <di****@dogmail.com> wrote in message
news:ic****************@nnrp1.ozemail.com.au...
So how do I tell it that Ctrl K has been pressed. If I can find that out,
I
can work the rest out for myself (hopefully).

dixie

"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote
in
message news:gbu0d.761$bj2.431@trnddc08...
> I forgot to mention that you can also use the KeyDown( ) event on a form to
> determine which keys where pressed, and if they are the correct
combination,
> then the KeyDown( ) event can execute your VBA procedure. However, this > will only be effective in the current form, whereas the AutoKeys
macro will
> be global and can be used for all database objects.
>
> HTH.
>
> Gunny
>
> See http://www.QBuilt.com for all your database needs.
> See http://www.Access.QBuilt.com for Microsoft Access tips.
>
> (Please remove ZERO_SPAM from my reply E-mail address, so that a

message > will be forwarded to me.)
>
>
> "'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote in
> message news:bZt0d.744$bj2.108@trnddc08...
> > Hi, Dixie.
> >
> > You can create a macro that will call a VBA function every time
you hit
a
> > certain key combination. Search Access Help for "AutoKeys."
> >
> > HTH.
> >
> > Gunny
> >
> > See http://www.QBuilt.com for all your database needs.
> > See http://www.Access.QBuilt.com for Microsoft Access tips.
> >
> > (Please remove ZERO_SPAM from my reply E-mail address, so that a

message
> > will be forwarded to me.)
> >
> >
> > "dixie" <di****@dogmail.com> wrote in message
> > news:lO***************@nnrp1.ozemail.com.au...
> > > I want to run an event when I press the Ctl key simultaneously

with the
> K
> > > key. How do I achieve this in VBA?
> > >
> > > dixie
> > >
> > >
> >
> >
>
>



Nov 13 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.