Hi,
I have 10 textboxes in the form and would like to do something when the user press ENTER, it go to the next textbox (like the tab key does). (Multi-line) text box is not the option.
THanks!
Printable View
Hi,
I have 10 textboxes in the form and would like to do something when the user press ENTER, it go to the next textbox (like the tab key does). (Multi-line) text box is not the option.
THanks!
you can use either textboxName.SetFocus or use the following codeSet FormName.KeyPreview = True in design mode. It will navigate based on the TabIndex valueVB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then SendKeys vbTab End If End Sub
This is fundamentally what ganeshmoorthy has, but I prefer using the KeyPress event.VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then ' Enter = Tab SendKeys "{tab}" KeyAscii = 0 End If End Sub
I agree, but I suggest writting it in the Form_KeyPress instead of Text1_KeyPress. If he uses text1_KeyPress then he has to write it in every textbox, if he does not have control array...Quote:
Originally Posted by Hack
Hi,Quote:
Originally Posted by ganeshmoorthy
I tried on both form keypress, keydown events, but not working.
Any reason why?
have you set the KeyPreview of the Form as I mentioned in my earlier post
Again, a matter of preference. If I'm naviagting a specific set of individual controls I prefer coding those individual controls rather than turning "control" over to the form itself.
In the project I just finished one screen is an Audited Financial Statement log. It has three sections: Statement of Operations, Balance Sheet and Cash Flow. Between those three sections there are 61 textboxs (including two separate comments textboxs) and I coded each of their KeyPress events for the Enter key. It may be a bit more work, but I like the control I have of what textbox does what when.
Quote:
Originally Posted by mapperkids
If KeyAscii = 13 Then ' Enter = Tab
SendKeys "{tab}"
KeyAscii = 0
End If
Yes, it works on the text1.keypress event, but NOT work on form.keypress event.
Thanks a lot !
ya, you may be right for certain projects, but I prefer coding in the Form which has got more controls, eventhough two controls have to be excludedVB Code:
If KeyCode = 13 Then If Not (Form1.ActiveControl.Name = "Text1" Or Form1.ActiveControl.Name = "Text2") Then SendKeys vbTab End If End Ifhave you set the Form's KeyPreview property to True...Quote:
Originally Posted by Mapperkids