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



The information in this article applies to:

  • Microsoft Office Access 2003
  • Microsoft Access 2002
  • Microsoft Access 2000

This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).

Moderate: Requires basic macro, coding, and interoperability skills.

SYMPTOMS

When you set the focus to the Header section of a subform, the GotFocus event of the first control in the tab order of the subform's Detail section is fired. This behavior occurs even if the control is not focused.

WORKAROUND

If the GotFocus event is defined for the first control in the Detail section, set the tab order of that control to a value other than first. To do so, set the Tab Index property of the control.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Problem

Caution If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database. To reproduce the problem, follow these steps:
  1. Start Microsoft Access, and then open the sample database Northwind.mdb.
  2. In the Database window, click Form on the Insert menu.
  3. In the New Form dialog box, click Design View, and then click OK.
  4. On the View menu, 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.
  9. On the File menu, click Close.
  10. Create another form that is named Form2.
  11. Add a command button named cmdButton to the Form2 form.
  12. Drag the subform form from the Database window to the Form2 form.
  13. Add the following code to the OnClick event of the cmdButton command button on the Form2 form:
    Me.subform.SetFocus
    Me.subform.Form!Command0.SetFocus
  14. Open the Form2 form in Form view.
  15. 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.

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:

Modification Type:MinorLast Reviewed:7/29/2004
Keywords:kberrmsg kbProgramming kbfunctions kbEvent kbprb KB824183 kbAudDeveloper