Shift-tab in keydown event




I have a userform with a bunch of textboxes, checkboxes, etc. I want
to allow the user to navigate through the controls using tab/shift-tab
OR Enter/arrow keys. Specifically, I would like Enter, right arrow,
or down arrow to equal a tab, and left arrow or up arrow to equal a
shift-tab. Here is my code:

Private Sub cmdButton_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = 13 Or KeyCode = 39 Or KeyCode = 40 Then KeyCode = 9
If KeyCode = 37 Or KeyCode = 38 Then
Shift=1 and KeyCode=9
'SendKeys "+{TAB}"
End If
End Sub

The first If statement works fine, but the second does not. I imagine
the problem relates to the fact that Shift is not a return integer,
like KeyCode, but the SendKeys statement that is commented out didn't
work either. How can I return a shift-tab using KeyCode, or is there
a better way to accomplish my goal?


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