Set Focus

  • Thread starter Thread starter Howard
  • Start date Start date
H

Howard

I need the code to set focus on a field in a subform. My
main form is called Customer, the subform is called
Components, and the field I want to put the focus on is
called Date. What is happening in my application is I'm
trying to use a pop-up calendar control. I have the
control set as invisible. Using the events in the form,
when I enter the field, I make the calendar control
visible, and when I exit the field, I make the calendar
control invisible. The problem is after I make the
calendar control invisible, the focus goes back to the
first field in the form instead of the next field in the
tab order. Therefore, I want to set the focus to the
proper field. Thanks!
-Howard
 
To set focus to a control in a subform, first set focus to the subform
control (the control that holds the subform), and then set focus to the
control on that subform:

Me.Subform.SetFocus
Me.Subform.Form.ControlName.SetFocus
 
Subform needs to be replaced by the name of the subform control (the control
that holds the subform, which name may or may not be the same name as that
control's SourceObject). Also, if the code that runs these steps is in
another form's module, replace Me with the full reference to that other
form:
Forms("Formname")!Subform.SetFocus
Forms("Formname")!Subform.Form.ControlName.SetFocus
 
Back
Top