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

Giving up focus rather than sending focus

Status
Not open for further replies.

Retsacnal

Programmer
Jan 24, 2002
5
0
0
AU
Hi,
Is it possible to simply have a control give up the focus (so that the focus moves to the next control in the tab index list). The reason I need to do this is that I've created a UserControl with four text boxs on it and I want the user to be able to type in text box 1 then hit enter and have the focus move to text box 2 and so on until text box 4. SetFocus is fine for text boxs 1, 2, and 3 but when the user hits enter in text box 4 I want the focus to be sent to what ever control is next in line after my UserControl. Being a UserControl, I created it so that I could use it in multiple places, so I don't know "inside" the code for the UserControl which control will be next so I can't call SetFocus on it. Another possibility could be if a UserControl can give up the focus to its containing window but I couldn't find anything on this in the help.

On a related problem is there any way to have SetFocus cause validation. The Validate event is happening if the user Tabs or clicks to change the focus from one text box to another but when I handle the Keypress event and change the focus when vbCr is pressed the Validate event isn't happening! Currently I'm explicitly calling the Validate event sub but that is just a work around that shouldn't be necessary, right?

Cheers,

Ryan.
 
I'm guessing that you have code in the KeyPress event of your textboxes.
Have a look at the code below and maybe it may be of help
Code:
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
  KeyAscii = 0
  SendKeys "{TAB}"
End If
End Sub
 
Thanks,
My next question was going to be how to best make the enter key behave like the tab key. If only I'd known about this magical SendKeys statement :)

Cheers,

Ryan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top