Move the focus to a specific control on a form.


   Object   The control to receive focus.

Use the SetFocus method when you want all user input to be directed at a specific object.

Reading some control properties requires the control to have the focus. For example, a text box must have the focus before you can read its Text property.

Setting some control properties requires the control to NOT have the focus. For example, you can’t set a control’s Visible or Enabled properties to False (0) when that control has the focus.

You can move the focus only to a visible control or form. A form and controls on a form aren’t visible until the form's Load event has finished. Use the Repaint method before SetFocus to ensure the control is visible.

If a form contains no enabled controls, then SetFocus will set focus to the form itself.

If a form contains one or more enabled controls attempting to move the focus to the form, will set focus to the control on the form that last received focus.

SetFocus is used when opening multiple copies of the same Access form.

To move the focus to a control on a subform, first move the focus to the subform control and then a second SetFocus for the control on the subform.

SetFocus is the preferred method for moving focus, rather than DoCmd.GoToControl




“When you write down your ideas you automatically focus your full attention on them. Few if any of us can write one thought and think another at the same time. Thus a pencil and paper make excellent concentration tools” ~ Michael Leboeuf


Access Form References - Reference controls on subforms.
SendKeys - Send one or more keystrokes to the active window as if typed at the keyboard.

Copyright © 1999-2024
Some rights reserved