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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering data in a text box

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I would like to a accept data entered into a text box by pressing the enter key after the text has been entered. Pressing the enter key will perform the same function as pressing another command button on the form. How do I go about doing this. I am kind of new to VB and any help would be appreciated.
John
 
Try this... place a text box and a command button on a form.
[tt]
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then Command1_Click
End Sub

Private Sub Command1_Click()
MsgBox "Enter was pressed."
End Sub
[/tt]

Press ENTER while in the text box and the code in the command button executes.
VCA.gif

Alt255@Vorpalcom.Intranets.com​
 
The ENTER key is a special case. If a command button has property DEFAULT set to TRUE then the following applies:

"Only one command button on a form can be the default command button. When Default is set to True for one command button, it's automatically set to False for all other command buttons on the form. When the command button's Default property setting is True and its parent form is active, the user can choose the command button (invoking its Click event) by pressing ENTER. Any other control with the focus doesn't receive a keyboard event (KeyDown, KeyPress, or KeyUp) for the ENTER key unless the user has moved the focus to another command button on the same form. In this case, pressing ENTER chooses the command button that has the focus instead of the default command button."
 
I think I know what you are pointing at. you probably want to create a form with many controls, and you want to navigate through them with ENTER.

you should do the following:
1. set the form property 'KeyPreview' to TRUE
2. put this code in the form code

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode=vbKeyReturn And Shift=0 Then
'call my validation procedure
End If
End Sub Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
I knew it would be easy. Setting the default to true did the trick. Thanks to alll who contributed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top