[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

settin focus using tabindex

Posted on 2004-08-05
3
Medium Priority
?
1,586 Views
Last Modified: 2013-12-25
i'm tryin to set focus in the next text box
by pressing vbKeyDown in the text box

there are three n boxes txt_1 , txt_2 and txt_3 ... txt_n

when i press down key in txt_1 focus should be set to txt_2
and from txt_2 to txt_3
and upto txt_n

i will call a function in each textboxes keydown event
which will shift the focus to the next text box

function :
private function shiftFocus(byval index as integer)
    dim i as integer
    i=index+1
    me.controls(i).setfocus ' this line is setting wrong focus
end function

call :

call (txt_1.tabIndex)

any solution to my problem is worth 500 points.
Thanks

0
Comment
Question by:amit_mi2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 11724066
Try use sendkeys function, like:

Private Sub txt_1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then SendKeys "{Tab}"
End Sub

in the case that the TabIndex(s) are in order

cheers
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 11730801
ryancys' comment is the pragmatic answer.

However,  to understand why your attempt did not work, you should understand that TabIndex is not the same as the index in the controls collection. Therefore you cannot address a control by its TabIndex. You would have to find it programatically:

Option Explicit

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
KeyCode = 9
    NextBox Text1
End Sub

Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
    NextBox Text2
End Sub

Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer)
    NextBox Text3
End Sub

Sub NextBox(TextX As Control)
    Dim ctl As Object
    Dim i As Integer
    Dim m As Integer
    Dim Minctl As Control
   
    m = TextX.TabIndex
    Set Minctl = Me.Text1
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox Then
            If ctl.TabIndex = TextX.TabIndex + 1 Then
                ctl.SetFocus
                Exit Sub
            End If
            If ctl.TabIndex < m Then
                m = ctl.TabIndex
                Set Minctl = ctl
            End If
        End If
    Next ctl
    Minctl.SetFocus 'last box reached, back to start
End Sub
0
 

Author Comment

by:amit_mi2
ID: 11741926
nice answer Graham
same thing i worked out
after posting
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question