|
-
Aug 3rd, 2005, 12:41 AM
#1
Thread Starter
New Member
moving cursor to next tabindex on enter key press
Hi
I have a form and I want to allow user to navigate all fields using "enter key" but I don't want to do it using arrays.I have to use this in many form so I need just one function which i will write inside form_keypress() event.It will read the current tabindex and shift cursor to next tabindex on enter ket press.
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
MsgBox KeyAscii
' THE CODE
End If
End Sub
Please reply ASAP.
thanks,
sincerely,
summerisland
-
Aug 3rd, 2005, 02:06 AM
#2
Re: moving cursor to next tabindex on enter key press
VB.NET MVP 2008 - Present
-
Aug 3rd, 2005, 03:04 AM
#3
Re: moving cursor to next tabindex on enter key press
Here is a simple single line code
For this code to work, first set KeyPreview = True at design time.
VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then SendKeys "{TAB}"
End Sub
-
Aug 3rd, 2005, 03:29 AM
#4
Lively Member
Re: moving cursor to next tabindex on enter key press
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys ("{tab}")
KeyAscii = 0
End If
End Sub
-
Aug 3rd, 2005, 03:46 AM
#5
Re: moving cursor to next tabindex on enter key press
Here is an alternative solution. It's more complicated, but may be of interest.
VB Code:
Option Explicit
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim c As Control
Dim f As Boolean
If KeyAscii = Asc(vbCr) Then
For Each c In Me.Controls
If c.TabIndex = ActiveControl.TabIndex + 1 Then
c.SetFocus
f = True
Exit For
End If
Next
'If we are at the end of the tab order then set focus to the first control.
If Not f Then Text1.SetFocus
End If
End Sub
This world is not my home. I'm just passing through.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|