Solved

How to cycle through controls using TAB?

Posted on 1998-12-03
10
222 Views
Last Modified: 2013-12-25
On one of my VB forms, I could use TAB to move between
controls according to TABINDEX. But when I come to the
highest TABINDEX, pressing TAB does not return me to the
lowest indexed control. Similar for Shift-TAB, it does not
bring me to the highest index control when I am at
TABINDEX 0. How can I change this?
0
Comment
Question by:angelany
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 2

Expert Comment

by:trillo
ID: 1488681
I don't know which controls you have on your form, but there are several controls (such as PictureBoxes) that accept TabStops but they don't appear to have the focus.... I suggest you to set to False the "tabStop" property of all controls in you form that don't need the input focus.

trillo
0
 
LVL 3

Expert Comment

by:traygreen
ID: 1488682
Ditto on trillo's comments.  Also things like tabs.
If you are having trouble finding out which control it is.....
Put MsgBox ActiveControl.Name in the lost focus for what you believe to be the last control in your tab sequence
run the app...set the cursor in what you believe to be the final control in the tab sequence and press tab.
The message box will tell you the name of the control that now has focus.  Set it's Tabstop to false and continue until the cursor goes where you want it to.
0
 

Author Comment

by:angelany
ID: 1488683
I have UserControls on my form, and they also contain UserControls that accept input,
and VB controls such as buttons.

Usually, if I have all VB controls, when I press TAB, the focus will cycle through all
eligible controls (textbox, button, etc), from tabindex 0, 1, ... to max tabindex, and
one more TAB brings the focus back to tabindex 0. This is visually obvious on the
screen: textbox gets cursor, and button get dashed outline inside the border.

Now what happens to me is that, when I TAB through all controls and come to the
highest tabindex control (e.g. a button), the focus does not move on any more when
I press TAB. It got "stuck". Similar for Shift-TAB when the order is supposed to be
reversed.

I know this should work because some other forms that have similar structure as
this form DO have the TAB key functional as expected. But I could not find out the
difference. Is there anything subtle about UserControls?
0
 
LVL 3

Expert Comment

by:traygreen
ID: 1488684
Just curious, but I am assuming there is no code on the control or form to suppress the tab key given focus on that last control?  Esp. since you are saying that the shift tab is not working either.  I had meant to post my answer as a comment, so go ahead and reject it.
If you would like, email me the form traygreen@hotmail.com and I'll take a quick look at it.
Tray
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 1488685
you can set the tab  index manually ,

in the last control in the sequence , on the Lost_focus event you can use the GetFocus method of the first control in the sequence.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:angelany
ID: 1488686
Setting the tabindex manually does not help. The focuses get stuck
at highest and lowest indeces.

Now my problem is half solved. Since the last item on the form is a command button,
I could use the following code to set focus to the first field, which is a textbox:

Private Sub cmdClose_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyTab Then
        abEffDt.SetFocus
    End If
End Sub

But while I am at the first field (the textbox), pressing Shift-Tab gives me a beep, and
the focus does not change. I can not use lastbutton_setfocus in the code of
firstfield_lostfocus since there are two directions where the focus can go
(TAB and Shift-Tab).

I can not post the form because it contains OCXs and will not show without
some services specific to our setup. I don't think there is anything in the code that suppresses TAB key.

I also noticed that the other forms that I claimed "working" all contain a tabstrip, which
has its tabindex at a higher level, while this form contains one and only UserControl.
0
 
LVL 2

Expert Comment

by:mkmccreary
ID: 1488687
What you need to do is check the Shift in the KeyDown event.  Your code should look something like this:

If KeyCode = vbKeyTab And (Shift And vbKeyShift) Then
    LastControl.SetFocus
End If

See if that works for you.

Later,
Martin

0
 
LVL 15

Expert Comment

by:ameba
ID: 1488688
angelany, I think your UserControl is having problems. Check property CanGetFocus, ForwardFocus.
It is not unusual to have focus problems with UserControls.

E.g. put two textboxes on usercontrol. When using Tab on your form (which also has textboxes), everything looks OK. But when shift-Tabing, guess what will happen? Try it!

The workaround: replace Usercontrol with normal controls, or put everything in usercontrol, so it is the only control on the form.
0
 
LVL 5

Accepted Solution

by:
AnswerTheMan earned 100 total points
ID: 1488689
perhaps u have a tab index set to an unvisible control or to some other element on your form
0
 
LVL 2

Expert Comment

by:mkmccreary
ID: 1488690
Sorry, the code I posted earlier has an error.  It should read:

If KeyCode = vbKeyTab And (Shift And vbShiftMask) Then
    MsgBox "Shift Tab"
End If

Good Luck,
Martin
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now