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

Moving focus after Enter is pressed

Status
Not open for further replies.

alr

Mechanical
Joined
Nov 12, 1999
Messages
20
Location
AU
I have a Combo Box and am using AddItem after the text is replaced/edited. After Enter is pressed I want the focus to then move to the Text Box below, so this entry can also be edited/replaced.

It has defeated me! Please experts help me.

Tony
 
Have you tried using the KeyPress event?
Code:
Private Sub cboDevice_KeyPress(KeyAscii As Integer)

   Select Case KeyAscii
      Case Asc(vbCr)
         KeyAscii = 0
         SendKeys vbTab
   End Select

End Sub
 
Thankyou CajunCenturion

I tried your suggestion and having reordered the tabs it worked very well.

Thankyou again Tony
 
Hi,

You could also try the following using the setfocus method (it isn't tab order dependent).

A simple form with a textbox and combo box in VB6...

Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Text1.SetFocus
End If
End Sub

Private Sub Form_Load()
Combo1.AddItem "Fred"
Combo1.AddItem "Bill"
Combo1.AddItem "Dave"
End Sub

 
AHay is correct, but does suffer from one potential drawback. If the user enters the data, ending with a Tab key, control then moves to one control, but if ending with a Return key, controls moves to a different control.

In some cases, that can lead to confusion on the part of the users, not understanding why the program behaves differently.
 
Just to take that thought a step further, you may want to rethink moving focus with the return key. Love 'em or hate 'em Microsoft set the standard with the Tab key. You may confuse users as to why the return key moves focus in your program but not in any other ones (or why the return key moves focus for this control but not any other controls even in your own program!).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top