Microsoft KB Archive/179707

= BUG: Pressing TAB Key on Form Does Not Change Focus =

Article ID: 179707

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 Q179707



SYMPTOMS
An ActiveX control is created using Visual Basic and compiled into an OCX file. The compiled OCX is then referenced in a Visual Basic standard EXE project. When the standard EXE project is run in the IDE, tabbing between the controls on the form and the ActiveX control results in a beep and the focus does not change. This problem occurs after the ActiveX control has shown a modal form.



RESOLUTION
This problem only occurs when a project in the IDE references the compiled OCX; the problem does not occur when the project is made into an EXE.

To work around this problem, create a project group and reference the ActiveX control from the ActiveX control project. Reference the compiled version of the ActiveX control just before you compile your Visual Basic project.



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



MORE INFORMATION
This section show you how to create a sample project that demonstrates this behavior.

Steps to Create the ActiveX control
 Start a new ActiveX Control project in Visual Basic. UserControl1 is created by default. Add a textbox to UserControl1.  Copy the following code to the Code window of UserControl1: Option Explicit

Private Sub Text1_DblClick Form1.Show vbModal End Sub

 Add a form to the ActiveX control project.  Add a CommandButton to Form1. Copy the following code to the Code window of Form1: Option Explicit

Private Sub Command1_Click Unload Me     End Sub

 Change the Project name to "TestControl" and select the File/Make TestControl.ocx menu option to create TestControl.ocx. After creating the control, save and close the project.</li></ol>

You are done creating the ActiveX control. The next section shows you how to create the Standard EXE project that uses the ActiveX control you just created.

Steps to Create Standard EXE Project
<ol> Start a new Standard EXE project in Visual Basic. Form1 is created by default.</li> Add an MDI Form to the project.</li> Set the MDIChild property of Form1 to True.</li> Reference the ActiveX control you compiled in the previous section by completing the following steps:

<ol style="list-style-type: lower-alpha;"> From the Project menu, click Components. The Components dialog box displays.</li> Select the Controls Tab. Check TestControl in the list box.</li> Click OK to close the Components dialog box.</li></ol> </li> Add two instances of the TestControl ActiveX control to Form1. Position the two ActiveX controls so both controls are visible on the form.</li> On the Run menu, click Start, or press the F5 key to start the program.

<ol style="list-style-type: lower-alpha;"> Press the Tab key to change the focus between the two controls.</li> Double-click the text box on one of the TestControl ActiveX controls. Form1 appears. Click the CommandButton to close the form.</li> Set the focus to one of the TestControl ActiveX controls.

RESULTS: Pressing the Tab key results in a beep and the focus does not change.</li></ol> </li></ol>

The next section shows how to work around this bug using the projects you created in the previous sections.

Workaround
<ol> Open the ActiveX control project you used to create the ActiveX control.</li> From the File menu, click Add Project to add a standard EXE project. Form1 is created by default. Set the MDIChild property of Form1 to true.</li> Close the ActiveX control project. Note than an ActiveX control is added to the toolbar.</li> <li>Add two instances of the ActiveX control to Form1. Position the two ActiveX controls so both controls are visible on the form.</li> <li>On the Run menu, click Start or press the F5 key to start the program.

<ol style="list-style-type: lower-alpha;"> <li>Press the Tab key to change the focus between the two controls.</li> <li>Double-click the text box on one of the TestControl ActiveX controls. A form is displayed. Click the CommandButton to close the form.</li> <li>Set the focus to one of the TestControl ActiveX controls.</li></ol>

You can now tab between the text boxes of both ActiveX controls.</li></ol>

Additional query words: user control kbVBp500bug kbVBp600bug kbVBp kbdsd kbDSupport kbControl

Keywords: kbbug KB179707

-

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

© Microsoft Corporation. All rights reserved.