Key events on user form

G

Guest

I'm trying to capture the keycodes so that the focus will move to a specific
control based on whether the user hits TAB or ENTER, or SHIFT+TAB after
entering data in a given text box on my form. I've been trying to do so from
the Key_Down event of the text box, but am not having much luck. Any help
will be greatly appreciated.
 
G

Guest

Modify this to do tab or enter or shift or whatever you want. Originally
posted by Ron DeBruin, tests for Control key being pressed. If you need help
modifying post.

Declare Function GetKeyState Lib "user32" _
(ByVal nVirtKey As Long) As Integer

Const VK_CONTROL As Integer = &H11 'Ctrl


Sub test()
If GetKeyState(VK_CONTROL) < 0 Then Ctrl = True Else Ctrl = False
If Ctrl = True Then
MsgBox "pressed"
Else
MsgBox "Not"
End If
End Sub



'And this in the sheet module

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Call test
End Sub
 
G

Guest

John,

The controls and keystrokes I'm trying to manipulate are on a user form, not
a spreadsheet. Does this matter? I thought their were internal VBA commands
that could be used to achieve my goal here without having to call an external
user library.

Ken
 

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