Set focus to main form from a subform

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I have a subform with datasheet view embedded in a main form. User uses the
"Return" or "Enter" key on the keyboard to navigate to the next control. It
is working on the controls on the main form, but how to program the subform
to go or set focus to a control in the main form. i.e. when the focus on a
record in the subform, user hit the "return/enter" key and it sets focus to
a control in the main form. Thanks
 
Couple of ways you can do this:

(1) Use the OnExit event of the control on the subform to set focus to a
specific control on the mainform:

Private Sub ControlNameOnSubform_Exit(Cancel As Integer)
Me.Parent.ControlNameOnMainForm.SetFocus
End Sub



(2) Use an almost invisible textbox as the last control in the subform's tab
sequence (textbox has height of zero and width of zero), and use that
textbox's GotFocus event to set focus to control on main form:

Private Sub TinyControlNameOnSubform_GotFocus()
Me.Parent.ControlNameOnMainForm.SetFocus
End Sub
 
Back
Top