Microsoft KB Archive/192196

= BUG: Unable to Tab Through Controls on UserControl =

Article ID: 192196

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q192196



SYMPTOMS
When a UserControl containing constituent controls is placed on a form, while the UserControl is the only control on the form, tabbing through the constituent controls does not loop.



CAUSE
This is because Visual Basic treats the UserControl as one control. Because there is no other control to give focus to, no looping occurs.



RESOLUTION
Manually set focus to the control with the TabIndex of 0 in the KeyPress event of the last control in the tab sequence. See the MORE INFORMATION section below for sample code.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



Steps to Reproduce Behavior
 Start a new Standard EXE project in Visual Basic. Form1 is created by default. From the File menu, add an ActiveX Control project. UserControl1 is created by default. Add three CommandButton controls to UserControl1. Close the UserControl1 window and add an instance of UserControl1 to Form1.

Note: In order to reproduce this problem, UserControl1 should be the only control on Form1. Save and run the project. Begin pressing the TAB key to tab through all the controls. Notice that the tab sequence does not loop through the controls on the UserControl.</li>  Stop the project and add the following code to the KeyPress event of the last control in the tab sequence for the UserControl: Private Sub Command3_KeyPress(KeyAscii As Integer) Dim Ctrl As Control Dim FirstTab As Integer Dim FirstCtrl As Control Dim Count As Integer

Count = 0 ' Loop though all the controls and find ' the last control in the tab order For Each Ctrl In Controls If Count = 0 Then FirstTab = Ctrl.TabIndex Set FirstCtrl = Ctrl End If           If Ctrl.TabIndex < FirstTab Then FirstTab = Ctrl.TabIndex Set FirstCtrl = Ctrl End If           Count = Count + 1 Next Ctrl

' Set focus to last control in the tab order If KeyAscii = 9 Then FirstCtrl.SetFocus End If     End Sub

</li> Save and run the project again. Note that the tab sequence now loops through all the controls on the UserControl.</li></ol>

Additional query words: kbDSupport kbDSD kbVBp kbVBp600bug kbVBp500bug kbCtrlCreate

Keywords: kbbug KB192196

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.