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

Move to next object 1

Status
Not open for further replies.

codo

IS-IT--Management
Oct 31, 2001
187
ID
I want everytime i push enter after input on textboxt the cursor move to the next object/textbox without have to writing code on object.keypress procedure (just like when i press Tab button it automaticaly move to the next object). is it possible?
or i want to make a code on object.keypress procedure where everytime i push Enter it goes to the next tabindex.
 
Something like this?
Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn And TypeOf Me.ActiveControl Is TextBox Then
    NextTextBox Me.ActiveControl
End If
End Sub

Private Sub NextTextBox(tbx As TextBox)
Dim ctl                         As Control
Dim tb                          As TextBox
Dim FoundIt                     As Boolean
Dim curindex                    As Integer
curindex = tbx.TabIndex

[COLOR=black cyan]' Look for the TextBox with the next highest TabIndex Value[/color]
For Each ctl In Me.Controls
    If TypeOf ctl Is TextBox And ctl.TabIndex > tbx.TabIndex Then
        If FoundIt Then
            If tb.TabIndex > ctl.TabIndex Then
                Set tb = ctl
                FoundIt = True
            End If
        Else
            Set tb = ctl
            FoundIt = True
        End If
    End If
Next

[COLOR=black cyan]' If you didn't find one then look for the TextBox with the
' smallest TabIndex value.[/color]
If Not FoundIt Then
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox Then
            If Not FoundIt Then
                Set tb = ctl
                FoundIt = True
            ElseIf tb.TabIndex > ctl.TabIndex Then
                Set tb = ctl
                FoundIt = True
            End If
        End If
    Next
End If

If FoundIt Then tb.SetFocus

End Sub
You will need to set the "KeyPreview" property of your form to TRUE.
 
I notice that although you have asked around 100 questions on the forums here, you haven't marked any of the answers as valuable, and I can only see one or two acknowledgements of other peoples responses. If you are not getting the answers that you need read faq222-2244 to see how to ask better questions. If you are getting the answers you need see faq222-2244 to see how to acknowledge the answers given.

Paragraph 16 of the FAQ explains about this being a two-way forum, to give guidance on answering other peoples questions, as I also notice that you haven't yet made any posts in other peoples threads.

For this question, look up KeyPreview property of the Form object.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Thanks Golom for the answer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top