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.
- In the GotFocus event of the TextBox control, add the following
code:
MsgBox "GotFocus Event For the Text Box is Called"
- Save the form as subform, and then close the form.
- Create another form that is named Form2.
- Add a command button named cmdButton to the Form2 form.
- Drag the subform form from the Database window to the Form2 form.
- 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
- Open the Form2 form in Form view.
- 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.