Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

↑ Back to the top


Workaround

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

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

Steps to reproduce the behavior

  1. Open the Northwind sample database in Microsoft Access.
  2. 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.
  3. In the New Form dialog box, click Design View, and then click OK.

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

    Note In Access 2007, right-click the form, and then click Form Header/Footer.
  5. In the Form Header section, add a Command0 command button.
  6. In the Detail section, add a TextBox control.
  7. In the GotFocus event of the TextBox control, add the following code:
    MsgBox "GotFocus Event For the Text Box is Called"
  8. Save the form as subform, and then close the form.
  9. Create another form that is named Form2.
  10. Add a command button named cmdButton to the Form2 form.
  11. Drag the subform form from the Database window to the Form2 form.
  12. 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
  13. Open the Form2 form in Form view.
  14. On the Form2 form, click cmdButton.
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.

↑ Back to the top


References

For more information about the GotFocus event, visit the following Microsoft Web site:For more information about subforms, visit the following Microsoft Web site:

↑ Back to the top


Keywords: kbexpertiseinter, kberrmsg, kbprogramming, kbfunctions, kbevent, kbprb, kbtshoot, KB824183

↑ Back to the top

Article Info
Article ID : 824183
Revision : 5
Created on : 4/12/2007
Published on : 4/12/2007
Exists online : False
Views : 392