Microsoft KB Archive/824183

= The GotFocus event of the first control in the Detail section of the subform is fired when you set the focus to the subform =

Article ID: 824183

Article Last Modified on 4/12/2007

-

APPLIES TO


 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition
 * Microsoft Access 2000 Standard Edition

-



This article applies to either a Microsoft Access database (.mdb) file or to a Microsoft Access database (.accdb) file, and to a Microsoft Access project (.adp) file. Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
In an Microsoft Access database, when you click a command button on a form to set the focus to the Header section of a subform that is included in the form, the GotFocus event of the control that is in the Detail section of the subform and has the Tab Index property set to 0 is called.

This behavior occurs even if the control is not focused.



WORKAROUND
To work around this problem, set the Tab Index property of the control to a value other than 0.



STATUS
This behavior is by design.



Steps to reproduce the behavior
 Open the Northwind sample database in Microsoft Access. In the Database window, click Form on the Insert menu.

Note In Access 2007, click Form Design in the Forms group on the Create tab. In the New Form dialog box, click Design View, and then click OK.

Note In Access 2007, skip this step. On the View menu, click Form Header/Footer.

Note In Access 2007, right-click the form, and then click Form Header/Footer. In the Form Header section, add a Command0 command button. In the Detail section, add a TextBox control.</li>  In the GotFocus event of the TextBox control, add the following code: MsgBox &quot;GotFocus Event For the Text Box is Called&quot; </li> Save the form as subform, and then close the form.</li> Create another form that is named Form2.</li> Add a command button named cmdButton to the Form2 form.</li> Drag the subform form from the Database window to the Form2 form.</li>  Add the following code example to the OnClick event of the cmdButton command button on the Form2 form to set the focus to the Header section of the subform. Me.subform.SetFocus Me.subform.Form!Command0.SetFocus </li> Open the Form2 form in Form view.</li> On the Form2 form, click cmdButton.</li></ol>

When you click the cmdButton command button, the GotFocus event of cmdButton is called. In the GotFocus event of cmdButton, the focus is set to the Command0 command button in the Header section of the subform. However, the focus is not set to the text box in the subform's Detail section, and the GotFocus event of the text box is called.

<div class="references_section">