Enter Key function as TAB Key

dineshkumaar

Member
Joined
Jun 5, 2009
Messages
21
Programming Experience
10+
Hello everybody

I have a Data Entry form. I wanted to make the Enter key work like TAB key so that if a user presses Enter key, the next control should get the focus key.
For this, I used the Forms KeyPreview on and Form's KeyUp Event to trap the Enter key and used the SendKeys.Send("{TAB}"). The problem is that to open this form there is a MenuToolStripItem. If Selects this MenuToolStripItem by pressing enter (not mouse click), this Enter key is processed by the DataEntry Forms KeyUp event and the focus goes to the second object instead of the first one.

Another problem is that .. suppose there is a textbox TaxType. if user Types 1 and press Enter, It should jump to the VAT textbox. for this i used Vattextbox.focus event if the of TaxType.Valideted event. But the focus moves to the next control after VATtextbox. alternatively if user presses TAB in TaxType textbox then it goes properly to VATtextbox.

I am facing this problem every time where i need to make Enter key work as TAB since long time. Any suggestions.

Regards
Thanks.
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
{Be hAppy}

Use Keypress Event of the TextBox1 and see if enter is pressed by:

If e.Keychar=vbcr then
Textbox2.Select
endif
 

dineshkumaar

Member
Joined
Jun 5, 2009
Messages
21
Programming Experience
10+
Thanks

Thanks for your Suggestions.

But I have around 20 textboxes on the form. do i need to write code for each textboxes keypress event or there is better way to accomplish this.


Regards
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
{Be hAppy}

Just include all controls like

Textbox1.KeyPress, Textbox2.KeyPress, Textbox3.keyPress and so on.

In code at the place of:

Textbox2.Select use:

Sendkeys.Send "{TAB}"
 

dongodu

New member
Joined
Nov 8, 2010
Messages
1
Programming Experience
Beginner
Not working with VB 6.0, need assistance
 
Top Bottom