ctrl + enter

S

seeker

I want an activity to happen when ctrl and enter combination is chosen. The
following code:
Private Sub txtNameKey_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn And Shift = 2 Then
blah
blah
blah
end if
end sub

when I hit ctrl and then enter as a combo populates keycode with 17
(vbkeyctrl) instead of 13 (vbkeyreturn) and shift is 2 as it should be but
the procedure does not run because the sub thinks that vbkeyctrl was chosen
instead of vbkeyreturn and vbctrlmask. Thanks for the wisdom and help
 
D

Dirk Goldgar

seeker said:
I want an activity to happen when ctrl and enter combination is chosen.
The
following code:
Private Sub txtNameKey_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn And Shift = 2 Then
blah
blah
blah
end if
end sub

when I hit ctrl and then enter as a combo populates keycode with 17
(vbkeyctrl) instead of 13 (vbkeyreturn) and shift is 2 as it should be but
the procedure does not run because the sub thinks that vbkeyctrl was
chosen
instead of vbkeyreturn and vbctrlmask. Thanks for the wisdom and help


I'm using Access 2003 to test; what version are you using?

When I press Ctrl+Enter, the KeyPress event fires twice: Once for the Ctrl
key alone, giving KeyCode = 17 and Shift = 2, and then a second time for the
Ctrl+Enter combination, giving KeyCode = 13 and Shift = 2. Thinking about
it, that's what one should expect. First the Ctrl key was pressed, and then
the Enter key was pressed while the Ctrl key was still down.

If you never get the (13,2) combination, I think you must be doing something
to prevent it. However, it's just possible there's a bug in one version of
Access; I can't rule that out yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top