oke:
Here's another way to do what you want that doesn't use SendKeys (which can do some strange things if you're not careful), but it involves making a control array out of your textboxes:
---------------------------
Private Sub txtNumbers_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 13 'Enter
If Index = 3 Then
cmdOk.value = True
Else
txtNumbers(Index + 1).SetFocus
End If
End Select
End Sub
---------------------------
ronze:
A form's KeyDown/Up and KeyPress events won't fire if you have controls on it that can have the focus. What you'll need to do is copy/paste your code into the KeyPress event of another control (which one depends on your GUI). Then SetFocus to that control whenever it's possible your users might press Enter. Hopefully that doesn't cause other problems, but depending on your app, it might. In that case, you can use a timer to call GetAsyncKeyState(vbKeyReturn) API. If this returns non-zero, Enter has been pressed, run your code.
Anyone else have a better solution to this?
~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.
-Ben Franklin