Microsoft KB Archive/209689

= ACC2000: How to Set Focus to a Subform Control Using GoToControl =

Article ID: 209689

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q209689



Novice: Requires knowledge of the user interface on single-user computers.

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



SUMMARY
To set the focus to a control on a subform, you can create a macro that uses the GoToControl action to first move to the subform (which is a type of a control), and then uses the GoToControl action again to move to a particular control on the subform.

NOTE: This article explains a technique demonstrated in the sample file, FrmSmp00.mdb. For information about how to obtain this sample file, please see the following article in the Microsoft Knowledge Base:

233324 ACC2000: Microsoft Access 2000 Sample Forms Database Available in Download Center



MORE INFORMATION
The GoToControl macro action does not allow you to use the full syntax for the ControlName argument as:   Forms![orders]![orders subform]![ProductID] If you use this syntax, you may receive the following error message:

There is no field named 'Forms![Orders]![Orders subform]![ProductID]' in the current record.

To work around this behavior, you need to set up a macro that first sets the focus to the subform control, and then sets the focus to a specific control on the subform.

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.

 Open the sample database Northwind.mdb.  Create the following new macro called GoToSubform:   Macro Name      Macro Actions -  GoToSubform     GoToControl GoToControl

GoToSubform Actions ---  GoToControl Control Name: Orders Subform GoToControl Control Name: ProductID  Open the Orders form in Design view.  Add a command button to the form and set the following properties:   Caption: Enter/Modify Orders OnClick: GoToSubform  Open the Orders form in Form view. Click the Enter/Modify Orders button. Note that the insertion point moves to the Product field on the Orders subform.</li></ol>

<div class="references_section">