AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

Moving between control with the enter key

If you want to have the focus move between the controls on a form when the enter key is pressed, you can with the SendKeys function.  The basis of the tip is to detect when the Enter key is pressed, and then Send the Tab key to the program.

You can detect when the user presses enter from the KeyPress event procedure by checking to see if the KeyAscii parameter is the character code 13. Then you can move the focus to the next control in the TabIndex order with the code:

SendKeys "{tab}"

You can move the focus to the previous control with the code:

SendKeys "+{tab}"

This technique works with most kinds of controls. However, it does not work with command button controls, because command buttons do not receive the KeyPress event when you press enter.

Code

Sub Text1_KeyPress (KeyAscii As Integer)
If KeyAscii = 13 Then
    SendKeys "{tab}"
    KeyAscii = 0
End If
End Sub

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/