Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make Enter key / Carriage Return can work ??

Status
Not open for further replies.

oke

Programmer
Dec 15, 2000
5
ID
I have problem in using Enter key / Carriage Return on TextBox in my application. If I use Enter key / Carriage Return in TextBox the cursor cannot move to another Text Box in running my aplication.
How I can set my Application to work like I want ??


Any help or suggestions appreciated

Rubi A.

 
If you want the Enter key to set focus on the next textbox, you need to convert {Enter} in to a {Tab}.
Put this global function in one of your modules:
Code:
Public Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        SendKeys "{TAB}"
        KeyAscii = 0
    End If
End Sub
Hope this helps!
 
Blast from the past!

I am trying to get vbKeyReturn to start a routine. here is the code. is there anyhting else i need to do?


Private Sub Form_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
If KeyAscii = vbKeyReturn Then
LstUSER_Click
LstUSER_DblClick
End If
End Sub

thanks
Christina
 
Sounds more like you want to make the users "enter action" respond as it does with tab.

Many ways come to mind.
Change the key in a keypress handler. Not sure how this will act.

Have the Enter event, often handled by a command button's click event, check for empty text boxes and transfer focus or proceeding with the done action.



Wil Mead
wmead@optonline.net

 
hmm

well i took the code off of a process like you just described, so i understand what you are saying but it isn't what i want.

when the user presses "Enter" I want the program to take what is highlighted in the list box as the expected result. whatever has the focus on the list box. the routine for this is set in the click and dbl_click calls

thanks
christina

 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top